码迷,mamicode.com
首页 > 其他好文 > 详细

经典类属性和新式类属性

时间:2017-11-14 14:39:00      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:put   content   color   style   col   delete   elf   and   ice   

经典类只@property 没有setter 和deleter

 

class A(object):
    def __init__(self,price):
        self.__price=price
    @property    
    def price(self):
        return self.__price
    @price.setter
    def price(self,value):
        self.__price=value
    @price.deleter
    def price(self):
        print ‘@price.deleter‘
a=A(1.23)
print(a.price)
a.price
=23.4
print(a.price)
del a.price

结果:
1.23
23.4
del attr
 

 

经典类属性和新式类属性

标签:put   content   color   style   col   delete   elf   and   ice   

原文地址:http://www.cnblogs.com/howhy/p/7831521.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!