#method English is the meaning of methods#Classmethod class Method #when a method in a class involves only the static properties of an operation class, logically we want to call this method directly through the class name to modify the static properties of the class, which can be used with this built-in adorner function#Staticmethod static Method#method of Class ClassmethodclassGoods:discount= 0.5#Discount def __init__(self, Name, price): Self.name=name self.__price=Price @propertydefPrice (self):returnSelf.__price*Goods.discountdefChange_discount (self, Newdiscount):#Modify DiscountGoods.discount =Newdiscountapple= Goods ('Apple', 5)Print(Apple.price)#2.5Apple.change_discount (2)#This can modify the discount, but the concept is not understandable, because the discount is modified by the whole supermarket discount, but here actually using Apple method to modify the class discount, is unreasonablePrint(Goods.discount)classGoods:discount= 0.5#Discount def __init__(self, Name, price): Self.name=name self.__price=Price @propertydefPrice (self):returnSelf.__price*Goods.discount @classmethod#methods that are modified by this adorner can also be called directly by the class name to the CLS Representative class, like self (representing the object) defChange_discount (CLS, newdiscount):#Modify DiscountCls.discount =Newdiscountapple= Goods ('Apple', 5)Print(Apple.price) Goods.change_discount (0.2)#you can then invoke the method directly from the class name to modify the discount for the entire class.Print(Apple.price)#1.0#static method of the Staticmethod class #In fully object-oriented programming, if a method has nothing to do with the object and is not related to the class, use Staticmethod to turn the method into a static methodclassLogin:def __init__(self, Name, password): Self.name=name Self.pwd=PassworddefLogin (self):Pass@staticmethod#the decorated method becomes a static method, which is not related to the object, and is not related to the class, n defget_usr_pwd (): USR= Input ('User name') PWD= Input ('Password') Login (usr, pwd) login.get_usr_pwd ()#in fully object-oriented programming, if a method has nothing to do with the object and has no relation to the class, then use Staticmethod to turn this method into a static method that can be called directly#class methods and static methods are called by the class.#objects can also invoke class methods and static methods, but they should not be used
Classmethod, Staticclassmethod built-in adorner function