0
点赞
收藏
分享

微信扫一扫

python property使用

凉夜lrs 2023-01-18 阅读 83

class Goods():
def __init__(self):
self._price = ""

@property
def price(self):
return self._price

@price.setter
def price(self, value):
self._price = value

@price.deleter
def price(self):
del self._price

g = Goods()
a = g.price
print(a)

g.price = 123
b = g.price
print(b)

del g.price

举报

相关推荐

0 条评论