1

When I was writing code, I noticed a feature was not working as it should. I figured out that the problem came from this strange behavior:

>>> [][:10]
[]

I was expecting this code to throw an error. Why doesn't it? What practical applications does this behavior have?

Pradhyum R
  • 113
  • 2
  • 12
  • 2
    The relevant part of the [doc](https://docs.python.org/3/tutorial/introduction.html) is "However, out of range slice indexes are handled gracefully when used for slicing:" – Rima Jun 02 '21 at 21:17
  • @ch2019 Yes, but why is it handled gracefully? Is there a way to turn this feature "off"? – Pradhyum R Jun 02 '21 at 21:18
  • "Is there a way to turn it off" - that's a different question. – mkrieger1 Jun 02 '21 at 21:21

0 Answers0