multi = [[0] * 5] * 3
其实,这样做是不对的,因为[0] * 5是一个一维数组的对象,* 3的话只是把对象的引用复制了3次
但是如下写法是对的:
multilist = [[0] * 5 for row in range(3)]
或者
multilist = [[0 for col in range(5)] for row in range(3)]
https://www.cnblogs.com/zqifa/p/python-list.html
multi = [[0] * 5] * 3
其实,这样做是不对的,因为[0] * 5是一个一维数组的对象,* 3的话只是把对象的引用复制了3次
但是如下写法是对的:
multilist = [[0] * 5 for row in range(3)]
或者
multilist = [[0 for col in range(5)] for row in range(3)]
https://www.cnblogs.com/zqifa/p/python-list.html