python property使用

凉夜lrs

关注

阅读 85

2023-01-18

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)

0 0 举报