I am studying lists and behavior occurs that I do not understand.
I know that when I link one list to another, a connection between them is created. And that when I use slicing a list, I create a copy of the list (no connection between them, that is, when it changes into mute, it does not change in another). However, when there are lists within lists, even with slicing, connection is made between lists.
For example:
>>> a = [[2, 3, 5], [1, 3, 5]]
>>> b = a[:]
>>> print(b)
[[2, 3, 5], [1, 3, 5]]
>>> b[0][1] = 100
>>> print(a[0][1])
100
>>> print(b)
[[2, 100, 5], [1, 3, 5]]
>>> print(a)
[[2, 100, 5], [1, 3, 5]]
That is, changed in the b
list, also changed in the a
list.
Why did this happen?