1. The prototype of the slice operator in Python
[Start:stop:step]
That is: [Start index: End index: Step value]
Start index: As in other languages, starting from 0. Sequence from left to right, the first value is indexed to 0, and the last is-1
End index: The slice operator is taken to the index and does not contain the value of the index.
Step value: The default is one after the other, and if 2, it means a separate fetch operation. The step value is positive to take from left to right and, if negative, to Right-to-left. The step value cannot be 0
Note: If it is string[:] The pattern, then is [Start:stop] 2. Example:
5 exam= "Abcdefghi"
6 print Exam[:-1]
7 print exam[2:]
8 print exam[:7:2]
9 print exam[:3:-1]
Output:
Abcdefgh
Cdefghi
Aceg
Ihgfe
Note: the last row, because the third parameter is-1, is output in reverse order, but the index is not in reverse sequence