python中的切片运算符

时间:2017-09-16 09:48:52

标签: python-2.7 python-3.x

>>> word="python"
>>> word[42]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: string index out of range
>>> word[4:42]
'on'
>>> word[42:]
''

我的问题是为什么切片操作符不能给IndexError

0 个答案:

没有答案