|The object that you want to extract a "sub-object" from|
|The index of |
|The (non-inclusive) index of |
|Allows you to select only every |
You can unify the concept of slicing strings with that of slicing other sequences by viewing strings as an immutable collection of characters, with the caveat that a unicode character is represented by a string of length 1.
In mathematical notation you can consider slicing to use a half-open interval of
[start, end), that is to say that the start is included but the end is not. The half-open nature of the interval has the advantage that
len(x) > =
n, while the interval being closed at the start has the advantage that
x is a list with
len(x) >= n, thus keeping consistency between indexing and slicing notation.