<分区>
这是一个 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'仍然获取值?