I wonder
a = [0] * 3
print(a)
b = [a] * 3
print(b)
b[0][0] = 1
print(b)
Why this code's output is
[0, 0, 0]
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
[[1, 0, 0], [1, 0, 0], [1, 0, 0]]
Why b[1][0] and b[2][0] are also changed?
I wonder
a = [0] * 3
print(a)
b = [a] * 3
print(b)
b[0][0] = 1
print(b)
Why this code's output is
[0, 0, 0]
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
[[1, 0, 0], [1, 0, 0], [1, 0, 0]]
Why b[1][0] and b[2][0] are also changed?