Both the static and class member methods of Python can be accessed by a class or instance, and the concepts are not easy to clarify, but there are differences:
1) Static methods do not need to pass in the self parameter, and class member methods need to pass in a CLS parameter representing this class;
2) from 1th, the static method cannot access the instance variable, but the class member method also cannot access the instance variable, but can access the class variable; 3) The static method is somewhat like the Function ToolPak, and the class member method is closer to the static method in the Java object-oriented concept. Static methods
@staticmethod
Def staticmd ():
print ' static method @classmethod
def CLASSMD (CLS):
print ' class method '
static method:Unable to access class properties, instance properties, equivalent to a relatively independent method, and the class actually has nothing to do, in other words, in fact, is placed in the scope of a class function.
class member methods:You can access class properties and cannot access instance properties.
Property Method:@property Python's built-in @property decorator is responsible for turning a method into a property call using the properties decorator, which allows the member function to be called read-only and does not provide setter and deleter
class C (object): def __init__ (self): = None @property def x (self): "" ","I ' m the ' X ' property. """ return self._x @x.setter def x (Self, value): = value @ X.deleter def x (self): del self._x
Python static Method class method Property method