# Author : Kelvin
# Date : 2019/1/25 15:20
class Foo:
def __init__(self):
self.original_price = 100
self.discount = 0.8 @property
def price(self):
new_price = self.original_price * self.discount
return new_price @price.setter
def price(self, val):
self.original_price = val @price.deleter
def price(self):
del self.original_price f = Foo()
print(f.price)
f.price = 200
print(f.price)
del f.price
print(f.__dict__) """输出结果:
80.0
160.0
{'discount': 0.8}
"""