I am reading the official python documentation on python classes here: https://docs.python.org/release/3.8.5/tutorial/classes.html?highlight=class.
In section 9.3.2, following an example of class definition
class MyClass:
    """A simple example class"""
    i = 12345
    def f(self):
        return 'hello world'
there is a remark:
So in our example,
x.fis a valid method reference, sinceMyClass.fis a function, butx.iis not, sinceMyClass.iis not. Butx.fis not the same thing asMyClass.f— it is a method object, not a function object.
I am a bit confused about the difference between a method object and a function object. To me they are both some object that can be called. After more reading, I think the difference is:
- A function object must receive a full list of argument(s) as in its definition.
- A method object receives some arguments implicitly, for example, the x.fmethod above, when called, receives the instanceximplicitly as its first argumentself.
I have some questions:
- Is this the correct understanding of the difference between a method object and function object?
- Is this the sole difference between them?
- Are there any other, maybe more complicated, examples that illustrates the difference?
