Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Inheritance
#8
(Aug-11-2018, 12:47 PM)ichabod801 Wrote: 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.

Thanks ichabod801 for your help.
Reply


Messages In This Thread
Inheritance - by Athul - Aug-09-2018, 08:03 AM
RE: Inheritance - by ichabod801 - Aug-09-2018, 12:54 PM
RE: Inheritance - by micseydel - Aug-09-2018, 06:24 PM
RE: Inheritance - by Athul - Aug-11-2018, 07:35 AM
RE: Inheritance - by yksingh1097 - Aug-11-2018, 09:37 AM
RE: Inheritance - by snippsat - Aug-11-2018, 10:23 AM
RE: Inheritance - by ichabod801 - Aug-11-2018, 12:47 PM
RE: Inheritance - by yksingh1097 - Aug-11-2018, 06:48 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020