Python 33rd days ---- static method, class method, attribute method, python 33rd days
@ Staticmethod after decoration, the methods in the class are converted to static methods
1 class a: 2 3 @ staticmethod4 def B (self): 5 print ('')
Static methods cannot access instance variables or class variables, which is equivalent to the toolkit in the class. For example, OS, system, and other import modules
@ Classmethod: After the decoration, the methods in the class are converted into class methods. The difference between class methods and common methods is that class methods can only be class variables, but cannot access instance variables.
1 class B (object): 2 name = 'A' 3 @ classmethod4 def cc (self): 5 print ('% s. l ..... '% name) 6 7 8 9 B. cc ()
@ Property: after decoration, convert the method methods in the class into static properties.
Static attributes
1 class Eat_food (object): 2 self. _ food = None # Set a private property 3 4 @ property 5 def eat (self): 6 print ('..... % s' % self. _ food) 7 8 @ eat. setter # assign 9 def eat (self, food): 10 print ('..... % s' % food) 11 self. _ food = food # Save it to the private attribute. Backup 12 13 @ eat. deleter14 def eat (self): 15 del self. _ food # Delete the private attribute that saves the assigned value, which is equivalent to deleting this attribute method.