<分区>
我有一个 Python 代码,我首先定义了两个列表,然后让它们相同,并在它们相同后对它们执行相同的操作 - 但结果不一样:
test1 = [[[0],[0]]]*2
test2 = [[0]]*2
test2[0] = [[0],[0]]
test2[1] = [[0],[0]]
print 'They are identical?:',test1 == test2 # gives True
# Now that test1 == test2 do the same operation on test list 1 and 2:
test1[0][0] = 2
test2[0][0] = 2
print test1
print test2
这给出了
[[2, [0]], [2, [0]]] # test1
[[2, [0]], [[0], [0]]] # test2
有人能给我解释一下区别吗?