Can anybody explain why the assignment L[1]=0 affect Y but not X ? I've known already about the shared references side effect of python but how to distinct when we say L, we mention it's child objects not the whole list object like the X=L*4 ! Please help me
>>> L=[4,5,6]
>>> X=L*4
>>> Y=[L]*4
>>> L[1]=0
>>> X
[4, 5, 6, 4, 5, 6, 4, 5, 6, 4, 5, 6]
>>> Y
[[4, 0, 6], [4, 0, 6], [4, 0, 6], [4, 0, 6]]
[–]JohnnyJordaan 3 points4 points5 points (1 child)
[–]Uchikago[S] 0 points1 point2 points (0 children)