myList = [[ 0 ] * 3 ] * 4
|
但是当操作myList[0][1] = 1时,发现整个第二列都被赋值,变成
[[0,1,0],
[0,1,0],
[0,1,0],
[0,1,0]]
myList
=
[([
0
]
*
3
)
for
i
in
range
(
4
)]
避免浅拷贝。。。
2024-01-31 17:29:46
myList = [[ 0 ] * 3 ] * 4
|
但是当操作myList[0][1] = 1时,发现整个第二列都被赋值,变成
[[0,1,0],
[0,1,0],
[0,1,0],
[0,1,0]]
myList
=
[([
0
]
*
3
)
for
i
in
range
(
4
)]
避免浅拷贝。。。