首页 > 编程语言 > 详细

python的property方法疑惑

时间:2019-10-10 17:35:13      阅读:76      评论:0      收藏:0      [点我收藏+]
技术分享图片
 @property
    def eat(self,):
        money=None
        print(%s is eating cost %s%(self.name,money))
    @eat.setter
    def eat(self,money):
        cost=money
        print(eating  cost %s%money)
    @eat.deleter
    def eat(self):
        cost=1
        print(del eat now cost :%s%cost)
View Code

初学者,随便写了

使用装饰器定义的property与setter和del,三者之间似乎是平行关系,除了定义后两者必须先定义property。

调用的时候三者也是互不影响,

难道他们只是三种不同的实现方式?

我原以为:del方法应该是删除了该属性,后续应该显示不存在该属性。

结果不是这样,有什么问题吗?

 

python的property方法疑惑

原文:https://www.cnblogs.com/leohg/p/11649104.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!