经典类只@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.4print(a.price)del a.price 结果:
1.23
23.4
del attr
时间: 2024-10-11 06:50:02