Sequence Concepts
In a shard rule, list, tuple, and STR (strings) can all be called sequences and can be sliced by rules.
Slicing operations
Note that the subscript 0 of the slice represents the first element of the order, 1 represents the first element in reverse, and the slice does not include the right boundary, such as [0:3] representing elements 0, 1, and 2, excluding 3.
L=[' A ', ' B ', ' C ', ' d ', 5]
1. Get the first 3 elements of a list
>>> l[0:3][' A ', ' B ', ' C ']>>> l[:3][' A ', ' B ', ' C ']
2. Get the second 3 elements of the list
>>> l[-3:][' C ', ' d ', 5]
Because the list does not include the right boundary, the right boundary of the last three elements is not specified.
3. Get all elements
>>> l[:][' A ', ' B ', ' C ', ' d ', 5]>>> l[0:][' A ', ' B ', ' C ', ' d ', 5]
4. Specify the growth step
>>> l=list (range) >>> l[0:101:10][0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
Specify 10 steps for a unit
Other slices
#!/usr/bin/env python3#-*-coding:utf-8-*-vlist=[' A ', ' B ', ' C ']vtuple= (' A ', ' B ', ' C ') vstr= ' abc ' Print (Vlist[0:2]); Print (Vtuple[0:2]);p rint (Vstr[0:2])
The output is:
======================== restart:c:/python35/list.py ========================[' A ', ' B '] (' A ', ' B ') AB