the role of double colons in Python [::]
Python sequence Slice addresses can is written as A[start:end:step] and any of the start, stop or end can is drop PED.
The Python sequence slice address can be written as [Start: End: Step], where the start and end can be omitted
Range (n) to generate a [0,n) interval integer
Range (10)
[0,1,2,3,4,5,6,7,8,9]
Start start ellipsis, default starts with item No. 0
Range (10) [: 10:2]
[0,2,4,6,8]
When the end is omitted, the default to the array is final.
Range (10) [1::2]
[1,3,5,7,9]
When the beginning and the end are not omitted
Range [2:6:] #step省略默认为1
[2,3,4,5]
Range (10) [2:6:1]
[2,3,4,5]
Step Step=n, starting from Start (also counting) every step interval, take a number, until the end of
Range (20) [:: 3]
[0,3,6,9,12,15,18]
When step equals negative number, take the count from right to left.
Range (10) [::-1]
[9,8,7,6,5,4,3,2,1,0]
Range (10) [::-2]
[9,7,5,3,1]
———————————— –2017.7.4 ——————————————————— –
"The role of single quotes in Python"
A[start:end]: The range is [Start,end]
A=[[1,2,3],[4,5,6],[7,8,9]]
B=a[1:2]
[[4, 5, 6]]
A[:end]: The range is [0,end]
A=[[1,2,3],[4,5,6],[7,8,9]]
B=A[:1]
[[1, 2, 3]]
A[start:]: range from start to last (including last)
A=[[1,2,3],[4,5,6],[7,8,9]]
B=a[1:]
[[4, 5, 6], [7, 8, 9]]