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