Aug-11-2018, 12:47 PM
The key point is that self is the instance. So you create the Animal class with an eat method.
Animal.eat
is unbound, because there is no instance. Since there is no instance, there is no self to automatically create. That's why you have to pass something to the self parameter. If you then create an instance (my_dog = Animal()
). You now have an instance, and the method is bound to that instance. Now you can call my_dog.eat()
and self (the instance my_dog) is automatically passed as the first parameter. Animal().eat()
work because Animal()
creates an instance (just one that is not referenced by a variable name). That instance is then automatically passed as self to the eat method call.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures