0

Here's an example of what I'm talking about:

word = "ribcage"
print(word[0:200])

I would have assumed the interpreter would return an "Out of Range" error, but it just printed the word out as if I had given it valid indexes. Tried the same thing with lists and got the same results.

What am I missing here? Does slicing ignore the bounds of lists and strings?

user62099
  • 11
  • 2

1 Answers1

0

Yes slices ignore bounds in pythons:

https://wsvincent.com/python-wat-slice-out-of-range/

(or handle them gracefully depending on your point of view)

dada_dave
  • 493
  • 4
  • 13