Python doc 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 sl
I came across the same question before and it's related to the language specification. According to assignment-statements,
If the left side of assignment is subscription, Python will call __setitem__ on that object. a[i] = x
is equivalent to a.__setitem__(i, x)
.
If the left side of assignment is slice, Python will also call __setitem__
, but with different arguments:
a[1:4]=[1,2,3]
is equivalent to
a.__setitem__(slice(1,4,None), [1,2,3])
That's why list slice on the left side of '=' behaves differently.