#静态属性的作用是吧类的方法隐藏起来 (can hide the logic behind it) so that the user feels that it is in the electrophoresis attribute, not the method class Static:attribute= ' Properties ' def __init__ (Self,parameter1, PARAMETER2,PARAMETER3): Self.parameter1 = parameter1 Self.parameter2 = parameter2 Self.parameter3 = P Arameter3 def test (self): return (' Test ', self.parameter1) @property def print_static (self): print (S Tatic.attribute) return (' This is the result of the static property%s%s '% (self.parameter1,self.parameter2,self.parameter3) ') s=static (' Hello ', ' World ', '! ') Print (S.test ()) print (s.print_static)
static method:
#静态方法只是名义上归类管理, cannot use class variables and instance variables, is the toolkit of the class # My personal understanding is that the tiger skin is a big flag, and the static method just borrows a separate function under the tree of the class static:attribute= ' Properties ' def __init__ ( Self,parameter): Self.parameter=parameter def Test (self): return (' Test ', Self.parameter) @staticmethod def print_static (a,b,c): print (Static.attribute) return (' This is a static method ', A+b+c) s=static (' Hello ') print (S.test () ) Print (Static.print_static (2,4,6))
Class method:
The @classmethod class method is to call the class itself's properties through a function inside the class ' Class class (): The properties of attribute= ' Classes #类的属性 def __init__ (self,parameter): #这里的self是一 Object Self.parameter=parameter #实例的属性 def test (self): print (self) return (' class method Test call ', Self.parameter) @classmethod # class methods can only call class properties, cannot invoke instance Properties def print_class (CLS): #这里的cls是一个类 print (CLS) return (' properties of the class called Through class ', CLS . Attribute) X=class (' attribute of instance ') print (X.test ()) print (x.parameter) print (Class.print_class ()) print (Class.attribute)
Python static properties, static methods, class methods