@staticmethod, @classmethod, @property usage and function
classFoo (object):def __init__(self): Self._name="Property Test" Print "Init" defTest (self):Print "class Method"@propertydefname (self):returnself._name @staticmethoddefStaticfun ():Print "static method function"@classmethoddefClassfun (CLS):Print "class method function"if '__main__'==__name__: Foo.staticfun () Foo.classfun () F=Foo ()Printf.name f.test ()
- @staticmethod: Static methods
- @classmethod: Class method
- @property: Calling a function as a class member property
In C + +, a function called directly by a class name is known as a static method, there is no difference between @staticmethod and @classmethod, and of course there are some subtle differences, @classmethod parameters that require an implicit pass-through class name.
Of course, unlike in C + +, a member method in C + + cannot be called by an instantiated object of a class, directly through the class name.
Python @staticmethod, @classmethod, @property