class People: x =2 def __init__(this,name,w,l): this.name = name this.w = w this.l =l def test2(self): print("我就看看") #靜態(tài)屬性 @property #定制靜態(tài)屬性方法,跟實例綁定,讓用戶感知不到后端的運行邏輯 def room(this): return this.w*this.l #類方法 @classmethod #類方法:跟類綁定,和實例沒有任何關系,只是類級別的操作時用,實例也可以調用 def tell_info(cls): print(cls) print(cls.x) #靜態(tài)方法 @staticmethod #靜態(tài)方法 ,一個類的工具包 跟實例和類都不綁定 ,不能使用實例變量和類變量 def wash_body():
|