python描述符装饰器 property的联合套用
def get_discount_price(f):def _f2(self):return f(self)*self.discountreturn _f2
class Product:def __init__(self, price, discount):self.price = priceself.discount = discount@property@get_discount_price def discount_price(self):return self.pricep = Product(100, 0.9)
# print(p.get_price())
print(p.discount_price)
运行结果:

本博客是博主个人学习时的一些记录,不保证是为原创,个别文章加入了转载的源地址,还有个别文章是汇总网上多份资料所成,在这之中也必有疏漏未加标注处,如有侵权请与博主联系。
如果未特殊标注则为原创,遵循 CC 4.0 BY-SA 版权协议。
