切片原型 strs = ‘abcdefg’
Strs[start: end:step]
切片的三个参数分别表开始,结束,步长
第一位下标为0,end位不取,如strs[1:3] = ‘bc’
如果start,end超出现有数组范围,按实际范围截断strs[-100:100]=’abcdefg’
Strs[1:5] = ‘bcde’ strs[1:5:2] = ‘bd’
Strs[5:1] = ‘’
Start为空,默认为负无穷 strs[:4] = ‘abcd’
End为空,默认为正无穷 strs[2:] = ‘cdefg’
Strs[:] = ‘abcdefg’
Strs[1:5:-1] = ‘’
Start为空,默认为正无穷 strs[:2:-1] = ‘gfed’
End为空,默认为负无穷 strs[4::-1] = ‘edcba’
Strs[::-1] = ‘gfedcba’
原文:http://www.cnblogs.com/alert123/p/5236693.html