python中的简单n x n矩阵不起作用

python中的简单n x n矩阵不起作用,python,arrays,matrix,Python,Arrays,Matrix,我用它来创建“x”的4x4矩阵: listof=[] #table nic=[] #row max = 4 #tabele size nic = ['x']*max #row of x-es listof = [nic]*max #table of rows print(listof) #it looks ok listof[1][1] ="o" #changing one x to o print(listof) # wrong since all rows have o on index 1

我用它来创建“x”的4x4矩阵:

listof=[] #table
nic=[] #row
max = 4 #tabele size
nic = ['x']*max #row of x-es
listof = [nic]*max #table of rows
print(listof) #it looks ok
listof[1][1] ="o" #changing one x to o
print(listof) # wrong since all rows have o on index 1
?为什么

顺便说一句:我知道如果我使用:

listof = [["x" for x in range(max)] for y in range(max)]
但是上面的代码有什么问题?
谢谢

问题在于,
listof
最终包含对同一列表的四个引用。因此,当您更改一行中的元素时,它将更改所有行中的元素