代码:
class Node:
def __init__(self, key, children=[]):
self.key = key
self.children = children
def __repr__(self):
return self.key
执行:
root = Node("root")
child = Node("child")
root.children.append(child)
print child.children
print root.children[0].children
结果:
[child]
[child]
这真的很奇怪,为什么?
Python 的版本是 2.7.2。