类装饰器 @property

1.作用:装饰在类中的方法之上,把类中的方法伪装成类的属性可以通过对象.的方式调用

class Student(object):
    def __init__(self, name, height):
        self.name = name
       
    @property
    def weight(self):
weight = height - 110
return weight
stu = Student('liming',180)
print(stu.weight)
原文地址:https://www.cnblogs.com/bigbox/p/11960976.html