【发布时间】:2011-11-16 02:36:04
【问题描述】:
这是一个python类:
class TxdTest(object):
def __init__(self, name = '', atrributes = []):
self.name = name
self.attributes = atrributes
然后我像这样使用它:
def main():
for i in range(3):
test = TxdTest()
print test.name
print test.attributes
test.name = 'a'
test.attributes.append(1)
那么,结果如何?结果是:
[]
[1]
[1, 1]
为什么类中的'self.attributes'仍然获得值?
【问题讨论】:
标签: python class constructor initialization