Reputation: 81721
Could somebody please elaborate this paragraph to me:
If you still don’t understand how methods work, a look at the implementation can perhaps clarify matters. When an instance attribute is referenced that isn’t a data attribute, its class is searched. If the name denotes a valid class attribute that is a function object, a method object is created by packing (pointers to) the instance object and the function object just found together in an abstract object: this is the method object. When the method object is called with an argument list, a new argument list is constructed from the instance object and the argument list, and the function object is called with this new argument list.
Especially the part:
If the name denotes a valid class attribute that is a function object, a method object is created by packing (pointers to) the instance object and the function object just found together in an abstract object: this is the method object.
Difference between Method Object and Function Object?
Thanks.
Upvotes: 0
Views: 58
Reputation: 184191
A method object is a wrapper for a function object that allows the function to be attached (bound) to an instance. The method object knows what instance it is bound to, and, when it is called, it calls the wrapped function, passing the instance as the first argument. In other words, the method object is responsible for the explicit passing of self
that is characteristic of Python.
Upvotes: 1