Python字符串截取

>>> str1 = '0123456789'
>>> print(str1[:-5])
01234
>>> str1 = '0123456789'
>>> print(str1[:-5:-3])
96
>>> 
>>> str1 = '0123456789'
>>> print(str1[-5:-3])
56
>>> print(str1[:-1])
012345678
>>> print(str1[::-1])
9876543210
>>> print(str1[::])
0123456789
>>> print(str1[::-3])
9630
>>> print(str1[::-])
SyntaxError: invalid syntax
>>> 

 

 print(str1[:-5:-3])

 

posted @ 2016-06-16 22:42  dmdoge  阅读(259)  评论(0编辑  收藏  举报