A step size of two will include only every other element of the interval between the start and the end: : Slice « List « Python Tutorial






numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

print numbers[0:10:2] 
print numbers[3:6:3]








7.23.Slice
7.23.1.Slicing to access ranges of elements
7.23.2.LHS slice and the RHS may each be of any length
7.23.3.Slicing Shorthand
7.23.4.The first is inclusive, and the second is exclusive
7.23.5.Slice more than what you have
7.23.6.Slice from the end
7.23.7.If the slice continues to the end of the sequence, you may simply leave out the last index
7.23.8.If the slice continues to the start of the sequence, you may simply leave out the first index
7.23.9.copy the entire sequence, you may leave out both indices
7.23.10.Another parameter, which normally is left implicit, is the step length
7.23.11.A step size of two will include only every other element of the interval between the start and the end:
7.23.12.if you want every fourth element of a sequence, you only have to supply a step size of four:
7.23.13.Negative step size
7.23.14.Slicing a List
7.23.15.End slice
7.23.16.Middle slice
7.23.17.Negative Indices
7.23.18.Revese and skip
7.23.19.The starting and ending indices can exceed the length of the string.