June 2017
Beginner
352 pages
8h 39m
English
Slicing is a form of extended indexing which allows us to refer to portions of a list. To use it we pass the start and stop indices of a half-open range, separated by a colon, as the square-brackets index argument. Here's how:
>>> s = [3, 186, 4431, 74400, 1048443]>>> s[1:3][186, 4431]
See how the second index is one beyond the end of the returned range. The slice [1:4] . Slicing extracts part of a list. The slice range is half-open, so the value at the stop index is not included:

This facility can be combined with negative indices. For example, to take all elements except the first and last: ...
Read now
Unlock full access