0

I am very confused while debugging my code.

a = [[0]*2]*3
a[2][1] = 2
print(a)

leads to and output of [[0, 2], [0, 2], [0, 2]]

while

b = [[0,0],[0,0],[0,0]]
b[2][1] = 2
print(b)

leads to and output of [0, 0], [0, 0], [0, 2]]

What I intended was latter. Why is the output as [[0, 2], [0, 2], [0, 2]] when using array repetition?

jamesdean
  • 21
  • 5

0 Answers0