Python:slice与indices
slice:
eg:
>>>e=[0,1,2,3,4,5,6]
>>>s=slice(2,3)
>>>e[s]
[2]
slice的区间左闭右开[)
>>>s
slice(2,3,None)
slice([strar,]stop[,step]),start缺少时就是0
indices:
eg:
>>>print(s.indices(100))
(2,3,1)
>>>print(s.indices(3))
(2,3,1)
>>>print(s.indices(2))
(2,2,1)
>>>e[s]
[2]
这个indices相当于stop的位置,只要是大于之前的stop索引,按之前的来,否则就取小索引