After @staticmethod decoration, the methods in the class are converted to static methods
1 class A: 2 3 @staticmethod 4 def B (self): 5 Print ('')
A static method cannot access an instance variable or a class variable, which is equivalent to a toolkit in a class. such as OS, System and other import modules are generally
@classmethod decorated, the methods in the class are turned into class methods, the difference between class methods and ordinary methods is that class methods can only access class variables and cannot access instance variables
1 class B (object): 2 name=" aa " 3 @classmethod 4 def CC (self): 5 print ( ' %s ..... "%name) 6 7 8 9 b.cc ()
@property decorate, turn the method methods in the class into static properties
How to use static properties
1 classEat_food (object):2Self.__food=none#set a private property3 4 @property5 defEat (self):6 Print('. ...%s'%self.__food)7 8@eat. Setter#You can assign a value to it once you decorate it again9 defEat (Self,food):Ten Print('. ...%s'%Food ) OneSelf.__food=food#Save to private property, alternate A - @eat. Deleter - defEat (self): the delSelf.__food#Deleting a private property that holds an assignment is equivalent to deleting the property method