python学习笔记 - @property
zihua
2014-01-17 18:01:03
点击: 968
|
收藏
-
class parrot(object):
-
def __init__(self):
-
self._voltage = 10
-
-
@property
-
def voltage(self):
-
return self._voltage
-
-
@voltage.setter
-
def voltage(self, new_value):
-
self._voltage = new_value;
-
-
if __name__ == "__main__":
-
p = parrot()
-
print p.voltage
-
p.voltage = 12
-
print p.voltage
原文链接:http://blog.chinaunix.net/uid-9162199-id-4082437.html