There are three main points of the python classmethod class method:
1 in Python, The. Class Method @ classmethod is a function modifier, which indicates that the next class method is used. What we usually see is the instance method. The first parameter CLS of the class method, and the first parameter of the instance method is self, which indicates an instance of the class.
2. A common object method requires at least one self parameter, representing a class object instance.
3
The class method has the class variable CLS passed in, so that you can use CLs for some related processing. In addition, when a subclass is inherited and this class method is called, The passed-in class variable CLS is a subclass rather than a parent class.
Class methods can be called through classes, just like C. F (), which is a bit similar to static methods in C ++,
You can also call it through an instance of the class, just like C (). F (), Here C (). After writing it like this, it is an instance of the class.
# Encoding = UTF-8
Class Info(Object):
@ Classmethod
Def Sayclassmethod(CLS):
Print 'Say% S' % CLS
Def Saymethod(Self):
Print 'Say% S' % Self
Test = Info()
Test.Saymethod()# Instance call Method
Test.Sayclassmethod()# Instance call Methods
Info.Saymethod(Test)# Class call instance method
Info.Sayclassmethod()# Class call MethodsLet's compare and run it.