![]() |
Class Objects... - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Class Objects... (/thread-8849.html) |
Class Objects... - zowhair - Mar-10-2018 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. RE: Class Objects... - Gribouillis - Mar-10-2018 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.
RE: Class Objects... - wavic - Mar-10-2018 class MyClass: def f(): passThe 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() |