[[0] * 3] * 3初始化的python 2d列表分配问题
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> a = [[0] * 3] * 3
>>> a
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>> a[1][1] = 1
>>> a
[[0, 1, 0], [0, 1, 0], [0, 1, 0]]
为什么a不是[[0, 0, 0], [0, 1, 0], [0, 0, 0]]
?
picture of program run at cmd