Open ubless607 opened 2 years ago
https://stackoverflow.com/a/5131563/8621823
Based on above answer, I agree with the author that References to the objects from original list are maintained.
It could confusing because that statement in the book requires understanding in depth about how python works.
Also the statement Modifying
is vague on whether each item of original list is mutable or not, though i guess most readers will assume immutable items.
For mutable items, this sure does affect the original
l = [[1,2],[3,4],[5,6]]
l_slice = l[:2]
l_slice[1].append(5)
print(l_slice) #[[1, 2], [3, 4, 5]]
print(l) #[[1, 2], [3, 4, 5], [5, 6]]
Thank you for the report! I think it's clear as it is, but I could potentially explain more about references vs. objects to make it super clear.
In page 45,
I think this should be changed into: