The value of Index 1 changes in all rows in method1. How should I create an ar1 array correctly?
method1:
ar1= [[0] * 3] * 3
ar1[0][1]=5
print(ar1)
method2:
ar2=[
[0,0,0],
[0,0,0],
[0,0,0],
]
ar2[0][1]=5
print(ar2)
output1:
[[0, 5, 0], [0, 5, 0], [0, 5, 0]]
output2:
[[0, 5, 0], [0, 0, 0], [0, 0, 0]]