Python in line with the sequence of an ordered sequence of support sections (slice), such as lists, strings, tuples.
Format: [start: end: step]
start: start index, starting from 0, -1 indicating the end
end: end index
step: step, end-start, when the step is positive, the value from left to right. Step is negative, the reverse value
Note sliced end result does not contain an index that does not include the last one, the last position -1 for the index list
a=[1,2,3,4,5,6]
b1 = a [:] # all omitted, taken on behalf of the entire content, may be used to copy a list to another list
print (b1)
Results: [1, 2, 3, 4, 5, 6]
b = a [0: -1: 1] # 0 to the end position from the start, incremented by 1 taken. End index position does not contain print (b) Results: [1, 2, 3, 4, 5]
c1 = a [: 3] # omitting the start position of the index, and the step size. The default starting position from the beginning, the default step size is 1, the end position of index 3 Print (C1) Results: [1, 2, 3]
c = a [0: 5: 3] # from the first position to the sixth position, takes a value of 3 for each print (c) Results: [1, 4]
d = a [5: 0: -1] # reverse value print (d) Results: [6,. 5,. 4,. 3, 2]
D1 = A [:: -. 1] Print (D1) Results: [6 , 5, 4, 3, 2, 1]
Source: https: //www.cnblogs.com/PPhoebe/p/6710055.html