Python 2.7 python中的切片运算符 >word=“python” >>>字[42] 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 索引器错误:字符串索引超出范围 >>>字[4:42] “开” >>>字[42:] ''

Python 2.7 python中的切片运算符 >word=“python” >>>字[42] 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 索引器错误:字符串索引超出范围 >>>字[4:42] “开” >>>字[42:] '',python-2.7,python-3.x,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' >>&g

我的问题是,为什么切片运算符不给出索引器?

的可能重复项您可以在这里找到答案:
>>> 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:]
''