I don't understand why the result of the following code is [1,[2,5]]
and not [3,[2,5]]
. Why is the element in the sublist changed but the element outside of the sublist isn't?
I'm new to Python so maybe I don't see something which should be very obvious. I've read about deep and shallow copies, but it didn't help.
a = [1,[2,3]]
b = a[:]
a[0] = 3
a[1][1] = 5
print(b)
I created the list slice on line 2. But since it has no start or end values, the slice equals the entire list, right? Then why does 3 change to 5, but 1 stays the same?