First, the list is sliced
"Forward Slice"
1, L[0:9] from the index is the element 0 interception, until the index is 9 stop, but does not include index 9.
If the starting index is 0, you can omit:
2, L[1:9] can also start from any index
3, L[1:] End index omitted, indicated until the end
4, l[:] Start index and end index at the same time omitted, means to copy a list out
5, L[1:10:2] The last 2 means that every two intercept a
"Reverse slices"
The index of the penultimate element is-1, again, the reverse slice contains the start index, and does not contain the end index.
1. Omit Start index
2. Omit End Index
3, start index, end index are not omitted
4, plus the interval
Second, slicing the tuple and string is exactly the same as list.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Slicing operations in Python