class Goods():
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, value):
self.original_price = value
@price.deleter
def price(self):
del self.original_price
obj = Goods()
print(obj.price)
obj.price = 200
print(obj.price)
del obj.price
class Goods():
def __init__(self):
#原价
self.original_price = 100
#折扣
self.discount = 0.8
def get_price(self):
#实际价格 = 原价 * 折扣
new_price = self.original_price * self.discount
return new_price
def set_price(self, value):
self.original_price = value
def delete_price(self):
del self.original_price
PRICE = property(get_price, set_price, delete_price, "价格属性描述")
obj = Goods()
print(obj.PRICE) #获取商品价格
obj.PRICE = 200 #修改商品价格
print(obj.PRICE)
del obj.PRICE #删除商品价格