class lazyproperty: def __init__(self,fun): self.fun=fun def __get__(self, instance, owner): print("get") print(‘===========>‘,self) print(‘===========>‘,instance) print(‘===========>‘,owner) if instance is None: return self res=self.fun(instance) setattr(instance,self.fun.__name__,res) return resclass Room: #area1=lazyproperty(area1) def __init__(self,name,width,length): self.name=name self.width=width self.length=length @property #把一个函数伪装成一个属性 def area(self): return self.width*self.length @lazyproperty def area1(self): return self.width*self.lengthr1=Room("卧室",6,5)# print(Room.__dict__)# print(r1.area) #实例调用print(r1.area1)# print(Room.area) #类调用# print(Room.area1)print(r1.area1)print(r1.area1)