The examples in this article describe Python's class and static methods. Share to everyone for your reference. The specific analysis is as follows:
Python does not have the static keyword in C + +, and how does it statically approach it? And what are some of the rare classes in other languages that are God's horse?
The implementation of static and class methods in Python is dependent on the Python modifiers.
Copy Code code as follows:
Class MyClass:
Def method (self):
Print ("Method")
@staticmethod
Def staticmethod ():
Print ("static method")
@classmethod
def classmethod (CLS):
Print ("class method")
Are you aware of common object methods, class methods, and static methods?
The object method has the self argument, and the class method has a CLS parameter, which is not required by the static method.
In C + + there is no class method with a conceptual
Copy Code code as follows:
Class A (object):
"This ia A Class"
@staticmethod
Def Foo1 ():
Print (called static method Foo1 () \ n)
@classmethod
def Foo2 (CLS):
Print ("Call class method Foo2 ()")
Print ("cls.__name__ is", cls.__name__)
A.foo1 ();
A.foo2 ();
The result:
Call static method Foo1 ()
Call class Method Foo2 ()
CLS.__NAME__ is A
I hope this article will help you with your Python programming.