0

Code:

ar1 = [[0, 0], [0, 0]]  
ar2 = [[0, 0]]*2  
print(ar1)  
print(ar2) 
  
print('') 
  
ar1[0][0] = 1  
ar2[0][0] = 1  
print(ar1)  
print(ar2)  

Exit

[[0, 0], [0, 0]]  
[[0, 0], [0, 0]]  
  
[[1, 0], [0, 0]]  
[[1, 0], [1, 0]]  

Why is there a 1?

The arrays are absolutely identical, what's the problem?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 2
    They are not identical. The `ar1` list contains 2 lists. The `ar2` list contains two references to a single list. – Tim Roberts Oct 24 '22 at 22:52

0 Answers0