Why does assigning past the end of a list via a slice not raise an IndexError? [duplicate]
This question already has answers here : Why does substring slicing with index out of range work? (3 answers) I'm working on a sparse list implementation and recently implemented assignment via a slice. This led me to discover some behaviour in Python's built-in list implementation that I find suprising . Given an empty list and an assignment via a slice: >>> l = [] >>> l[100:] = ['foo'] I would have expected an IndexError from list here because the way this is implemented means that an item can't be retrieved from the specified index:: >>> l[100] Traceback (most recent call last): File "