1 # Author : Kelvin 2 # Date : 2019/1/25 15:20 3 class Foo: 4 def __init__(self): 5 self.original_price = 100 6 self.discount = 0.8 7 8 @property 9 def price(self):10 new_price = self.original_price * self.discount11 return new_price12 13 @price.setter14 def price(self, val):15 self.original_price = val16 17 @price.deleter18 def price(self):19 del self.original_price20 21 22 f = Foo()23 print(f.price)24 f.price = 20025 print(f.price)26 del f.price27 print(f.__dict__)28 29 """输出结果:30 80.031 160.032 {'discount': 0.8}33 """