I have 2 examples below:
Example 1:
simplelist = [0] * 2
for i in range(2):
simplelist[i] = i
print(simplelist)
result: [0, 1]
Example 2:
listinlist = [[0]] * 2
for i in range(2):
listinlist[i][0] = i
print(listinlist)
result: [[1], [1]]
As you can see, in the 1st example, the two 0s appear not related to each other, and the code works as expected. However, when I replace the 0s with [0]s in example 2, the two [0]s appear related as if they are referenced to the same object. I think when I assign values to each of them, I assign values to the same object twice, so the second value 1 overwrites the first value 0. Please correct me if I am wrong and help me understand this issue. If you think it is not a referencing issue, please also share your opinion.