可能重复:
Python 列表中的意外功能
所以我对 Python 比较陌生,并且在使用 2D 列表时遇到了麻烦。
这是我的代码:
data = [[None]*5]*5
data[0][0] = 'Cell A1'
print data
这是输出(为便于阅读而格式化):
[['Cell A1', None, None, None, None],
['Cell A1', None, None, None, None],
['Cell A1', None, None, None, None],
['Cell A1', None, None, None, None],
['Cell A1', None, None, None, None]]
为什么每一行都被赋值?