In a Python slice, the stride sets the interval between selected elements: `sequence[start:stop:stride]`. A positive stride selects from left to right; a negative stride selects from right to left. For example, `numbers[::3]` takes every third element, while `numbers[::-1]` reverses the list. section 4.1.1
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] assert numbers[2:5:2] == [3, 5] #1 assert numbers[::3] == [1, 4, 7] #2 assert numbers[::-1] == [9, 8, 7, 6, 5, 4, 3, 2, 1] #3
Compare a slice with stride 2, one with stride 3, and a reverse slice. section 4.1.1
Stride also works in list slice assignment. Assigning to `numbers[::2]` replaces every second item in the selected list positions. section 4.1.4
numbers[::2] = [0, 0, 0, 0] numbers # output: [0, 1, 0, 16, 0, 18, 0, 20]
See a list updated at every second position through strided slice assignment. section 4.1.4







