python @property装饰器
2019-11-24 13:16 清风软件测试开发 阅读(233) 评论(0) 编辑 收藏 举报python @property装饰器
class Goods: name = '笔记本' @property def price(self): print('print价格是:0.01元!!!') return 'return价格是:0.02元!!!' obj = Goods() print('*************0000*****************') obj.price print('*************111************') Goods().price print('*************222*****************') print(obj.price) print(Goods().price) print('*************333*****************') obj.price() print('*************444*****************') Goods().price() print('*************555*****************') print(obj.price()) print(Goods().price())
输出:
*************0000***************** File "E:/python_projects/practises/practise20191116/p20191124.py", line 100, in <module> print价格是:0.01元!!! obj.price() *************111************ TypeError: 'str' object is not callable print价格是:0.01元!!! *************222***************** print价格是:0.01元!!! return价格是:0.02元!!! print价格是:0.01元!!! return价格是:0.02元!!! *************333***************** print价格是:0.01元!!! Process finished with exit code 1