To use a static method in a class, precede the class member function with the @staticmethod tag to indicate that the following member function is a static function. The advantage of using static methods is that you do not need to define an instance to use this method. In addition, multiple instances share this static method.
# Spec: own members to access, in addition to the methods in the class, methods in the class to access the object # through the class to access the: Class property, static method # through the object to access the: Object properties, Methods in the class # static methods exist in the sense that you do not need to create an object to execute the methodclassAObject): Country='China'def __init__ (self,place): Self.place=Place def weather (self): print (Self.place+'Sunny Day') @staticmethod def temperature (): Print ('accessing static methods by Class ...') @staticmethod def func (A, B): Print ('static methods can pass parameters:', A, b) cc= A ('Changchun') Cc.weather () print (A.country) a.temperature () A.func (1,2)
static methods in class