我有以下代码:
games = rotations = 4
l = [ [ [""] * 3 ] * games ] * rotations
for i in range(rotations):
for j in range(games):
l[i][j][2] = j + 1
print(l)
l是
[[['', '', ''], ['', '', ''], ['', '', ''], ['', '', '']], [['', '', ''], ['', '', ''], ['','', ''], ['', '', '']], [['', '', ''], ['', '', ''], ['', '', ''], ['', '', '']], [['', '', ''], ['', '', ''], ['', '', ''], ['', '', '']]]
因此循环后应该打印
[[['', '', 1], ['', '', 2], ['', '', 3], ['', '', 4]], [['', '', 1], ['', '', 2], ['', '', 3], ['', '', 4]], [['', '', 1], ['', '', 2], ['', '', 3], ['', '', 4]], [['', '', 1], ['', '',2], ['', '', 3], ['', '', 4]]]
但它正在打印
[[['', '', 4], ['', '', 4], ['', '', 4], ['', '', 4]], [['', '', 4], ['', '', 4], ['', '', 4], ['', '', 4]], [['', '', 4], ['', '', 4], ['', '', 4], ['', '', 4]], [['', '', 4], ['', '',4], ['', '', 4], ['', '', 4]]]
为什么会这样?
谢谢