1, static properties. @property. The function is to encapsulate the functions of a class into similar data attributes.
class Student (object): School='szu' @property def printmassage (self): Print ('aaaa') S1=Student () s1.printmassage #aaaa
2, the class method: Is the class object has the method, needs to use the decorator @classmethod to identify it as the class method, for the class method, the first parameter must be the class object, generally takes cls as the first parameter, can through the instance object and the class object accesses.
Class methods generally have two functions: one is to access the class properties. The second is to modify the class properties
class Student (object): School='szu' @classmethod def Printmassage (CLS): print(cls.school) S1=Student () Student.printmassage () #szus1.printmassage () #Szu
3, static method: Static method is actually independent, depending on the class, but the actual is only to adjust the relationship. Just nominal collation management, is actually a toolkit that can be called by classes and instances. A static method cannot call a class method directly, and a call must be called with the class name.
classStudent (object): School='Szu'@staticmethoddefprintmassage ():Print(student.school) @staticmethoddeffunc (x, y):Print(x, y) s1=Student () student.printmassage ( )#SzuS1.printmassage ()#SzuStudent.func ()#1 2S1.func (ON)# the
Static properties, class methods, static methods for Python classes