python切片解析
切片原型 strs = ‘abcdefg’
Strs[start: end:step]
切片的三个参数分别表开始,结束,步长
第一位下标为0,end位不取,如strs[1:3] = ‘bc’
如果start,end超出现有数组范围,按实际范围截断strs[-100:100]=’abcdefg’
- Step为空时,缺省值为1
Strs[1:5] = ‘bcde’ strs[1:5:2] = ‘bd’
- Step为正时,start<end,否则为空
Strs[5:1] = ‘’
Start为空,默认为负无穷 strs[:4] = ‘abcd’
End为空,默认为正无穷 strs[2:] = ‘cdefg’
Strs[:] = ‘abcdefg’
- Step为负时, start>end, 否则为空
Strs[1:5:-1] = ‘’
Start为空,默认为正无穷 strs[:2:-1] = ‘gfed’
End为空,默认为负无穷 strs[4::-1] = ‘edcba’
Strs[::-1] = ‘gfedcba’