Home > other >  python
python

Time:09-22

CodePudding user response:

The class Dog:
Def __init__ (self, name) : there is space behind # def, two _ between the self and so is the init,
The self. The __name=name # there is no indentation, lead to an error,
Self. __age=None
Print (self __name, 'generate success')
Def set_age (self, age) :
If not isinstance (age, int) :
Print (' the age of the input must be a number! ')
Return False
If age<=0:
Print (' age must be greater than zero! ')
Return False
Self. __age=age
Def play (self) :
Print (' auf! I this year ', the self. __age)
Dog dog=(' prosperous wealth ')
T set_age (' hello ')

CodePudding user response:

You write this... Obviously still don't understand what is the function what object is more look at basic
Def behind said define a function to the blank space to write __init__ (self. Name), : after the code to a new line indentation