Given the expressions:
>>> l = [1,2,3]
>>> l[10:20] = [4,5]
>>> l
[1, 2, 3, 4, 5]
Why doesn't Python nag about the nonexistent items meant to be deleted? l.remove(55)
does raise a ValueError.
Given the expressions:
>>> l = [1,2,3]
>>> l[10:20] = [4,5]
>>> l
[1, 2, 3, 4, 5]
Why doesn't Python nag about the nonexistent items meant to be deleted? l.remove(55)
does raise a ValueError.
l.remove(55)
Raises an error because you don't have the value 55 in your list.
On the other hand, l[10:20] = [4,5]
is not crashing your code because that slicing
method will try to add elements on those indexes, if it can't, it will be adding the new elements in the last position of your array.
Also, if you try to do (for example) l[10]=10
, this will Raise the exception: IndexError: list index out of range