2
>>> 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:]
''

My question is that why slice operator doesn't give IndexError?

Tometzky
  • 22,573
  • 5
  • 59
  • 73
  • 5
    Possible duplicate of [Why substring slicing index out of range works in Python?](https://stackoverflow.com/questions/9490058/why-substring-slicing-index-out-of-range-works-in-python) – Jonathan Sep 16 '17 at 10:24
  • You can find the answer here: https://stackoverflow.com/questions/9490058/why-substring-slicing-index-out-of-range-works-in-python – Jonathan Sep 16 '17 at 10:24

0 Answers0