class People: x =2 def __init__(this,name,w,l): this.name = name this.w = w this.l =l def test2(self): print("我就看看") #静态属性 @property #定制静态属性方法,跟实例绑定,让用户感知不到后端的运行逻辑 def room(this): return this.w*this.l #类方法 @classmethod #类方法:跟类绑定,和实例没有任何关系,只是类级别的操作时用,实例也可以调用 def tell_info(cls): print(cls) print(cls.x) #静态方法 @staticmethod #静态方法 ,一个类的工具包 跟实例和类都不绑定 ,不能使用实例变量和类变量 def wash_body():
|