# 先回顾一下 class Room: def __init__(self,name,width,length): self.name = name self.width = width self.length = length @property def area(self): return self.width * self.length r1 = Room('wang',100,100) print(r1.area) class Lazyproperty: def __init__(self,func): self.func = func def __get__(self,instance,owner): print("我们自己定义的属性") if instance is None: return self return self.func(instance) class Room: def __init__(self,name,width,length): self.name = name self.width = width self.length = length @Lazyproperty # area = Lazyproperty(area) # 现在area是一个类,而不是函数 def area(self): # print(self.area) return self.width * self.length r1=Room('alex',1,1) print(r1.area)