# 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}
"""
相关文章
- Falsk的模板分配和蓝图、定制错误信息、 和补充
- MySQL服务相关
- fastCMS数据库相关操作类
- python学习----pearsonr(x,y)相关系数计算
- 音乐相关数据集介绍
- C# 使用Environment获取当前程序运行环境相关信息
- NX二次开发-Block UI C++界面Object Color Picker(对象颜色拾取器)控件的获取(持续补充)
- 【SpringBoot】MyBatis-plus 报错 Property ‘sqlSessionFactory‘ or ‘sqlSessionTemplate‘ are required
- 物联网相关
- 《嵌入式Linux基础教程》补充阅读建议电子数目下载