Why does somelist[len(somelist)] generate an IndexError but not somelist[len(somelist):]?

list, python, slice

Solution

Here's something from the documentation. There are specific rules around slicing of any iterable; of particular note is #4, emphasis mine:

The slice of `s` from `i` to `j` is defined as the sequence of items with index `k` such that `i <= k < j`. If `i` or `j` is greater than `len(s)`, use `len(s)`. If `i` is omitted or `None`, use `0`. If `j` is omitted or `None`, use `len(s)`. If `i` is greater than or equal to `j`, the slice is empty.

Problem

I understand that `somelist[len(somelist)]` cannot access an index that is outside of the defined list - this makes sense. But why then does Python allow you to do `somelist[len(somelist):]`? I've even read that `somelist[len(somelist):] = [1]` is equivalent to `somelist.append(1)` But why does slice notation change the fact that the index "len(somelist)" is still outside the range of the list?

Original source