In C + + classes, there are two kinds of functions: ordinary member functions and static member functions, the difference being that member functions are called through class instances, and static member functions are called through the class name. In essence, the member function will pass the this pointer as the first argument by default when called, and the static member function does not need to bind the this pointer.
In Python's class design, you can say that this implicit behavior of C + + is explicitly expressed.
Class Test (object): def __init__ (self): pass def func1 (self): pass @classmethod def Func2 (CLS): pass @staticmethod def func3 (); Pass
A normal instance member function binds a self parameter (that is, a reference to the instance that invokes it) when called.
Class method binds the class name
Static methods are completely unbound
Note that the definition of static methods and class methods requires the use of function modifiers as above. Of course you may also see this practice in the old Code (which is equivalent):
Class Test (object): def __init__ (self): pass def func1 (self): pass def func2 (CLS): Pass Func2 = Classmethod (FUNC2) def func3 (): pass func3 = Staticmethod (func3)
function call bindings in Python, static methods, and class methods