Python docs says that slicing a list returns a new list.
Now if a "new" list is being returned I've the following questions related to "Assignment to slices"
a = [1, 2, 3]
a[0:2] = [4, 5]
print a
Now the output would be:
[4, 5, 3]
- How can something that is returning something come on the left side of expression?
- Yes, I read the docs and it says it is possible, now since slicing a list returns a "new" list, why is the original list being modified? I am not able to understand the mechanics behind it.