When computing slices, you may also specify a stride, which is the length of the step from one index to the other. The default stride is 1.
Here is an example:
L = list(range(100)) L[:10:2] # [0, 2, 4, 6, 8] L[::20] # [0, 20, 40, 60, 80] L[10:20:3] # [10, 13, 16, 19]
Note that the stride may also be negative:
L[20:10:-3] # [20, 17, 14, 11]
It is also possible to create a new list that is reversed, using a negative stride:
L = [1, 2, 3] R = L[::-1] # L is not modified R # [3, 2, 1]
Alternatively, you might want to use the method reverse, which is explained in Section 3.1.4: List methods.