Take a look at this code
a=[[0]*3]*3
a[1][1]=1
for x in a:
print(*x)
#output
# 0 1 0
# 0 1 0
# 0 1 0
and take a look at this code
a=[
[0,0,0],
[0,0,0],
[0,0,0]
]
a[1][1]=1
for x in a:
print(*x)
#output
# 0 0 0
# 0 1 0
# 0 0 0
I do believe that in both cases , the array a is same. But why the results are different then.
a=[1, 2, 3]; b=a; b[0]=9. In this example yo have one list only and a and B both point to the same list, so changing the element in b will change it in a also since they both point to same list. In your first example you do the same thing. you create one list then make 3 copies that point to that 1 list. So if you make a change in either of the copies it will reflect in all of them since there is only one list and they all point to it