コード:
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 です。