class Number():
def __init__(self,n):
self._n=n
self._changed=None
@property
def n(self):
return self._n
@property
def changed(self):
return self._changed
@n.setter
def n(self, val):
# while setting the value of n, change the 'changed' value as well
self._n = val
self._changed = True
a = Number(8)
print(a.n) #prints 8
a.n=9
print(a.n) #prints 9
print(a.changed)
适当使用
@propety
可能返回:
相关问题 更多 >
编程相关推荐