类方法classmethod

类方法classmethod,cls
#
静态属性@property和静态方法self #静态属性就是数据属性 class Room: tag=1 # def __init__(self,name,width,owner):#self表示对象,可以大家用的如p1 # self.name=name # self.owner=owner # self.width=width @classmethod#调用类方法类名直接点函数就可以用不需要self def tellinfo(cls,name): print(cls) print('-->',cls.tag,name) # @property#属性 # def cal(self): # print('%s住的%s大小是%s平方米' % (self.owner, self.name, self.width)) # r1=Room('卧室',23,'rof') # # r1.cal()当有property时就不能加点调用 # r1.cal#property函数方法不加括号直接执行 Room.tellinfo('asd')#类直接调用的方法
原文地址:https://www.cnblogs.com/wfl9310/p/9055644.html