@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)
初学者,随便写了
使用装饰器定义的property与setter和del,三者之间似乎是平行关系,除了定义后两者必须先定义property。
调用的时候三者也是互不影响,
难道他们只是三种不同的实现方式?
我原以为:del方法应该是删除了该属性,后续应该显示不存在该属性。
结果不是这样,有什么问题吗?
原文:https://www.cnblogs.com/leohg/p/11649104.html