But x.f is not the same thing as MyClass.f — it is a method object, not a function object.
What is the difference between method and function here, as I learned that method and functions are same things.
It is very simple, MyClass.f
is the function object that was defined in MyClass, while x.f
is an entity named 'bound method' which essentialy means a pair containing an instance and a function glued together.
class MyClass:
def f():
pass
The function f() is defined inside the class MyClass and that is the reason to call it method.
Calling the method:
MyClass.f()
Creating an instance of the class:
x = MyClass()
Now, you create an instance of MyClass called x. Then call the method:
x.f()