[[0] * 3] * 3初始化的python 2d列表分配问题

时间:2018-11-07 12:47:05

标签: python

[[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

0 个答案:

没有答案