I want to assign value to 2d array in for loop
This is my code
num = 0
n = 3
arr = [[0] * n] * n
for i in range(n):
for j in range(n):
arr[i][j] = num
num +=1
The output I expected is
[0, 1, 2]
[3, 4, 5]
[6, 7, 8]
But actual output is
[6, 7, 8]
[6, 7, 8]
[6, 7, 8]
Is there any way to fix this?