Why does substring slicing with index out of range work?

前端 未结 3 1239
栀梦
栀梦 2020-11-22 02:32

Why doesn\'t \'example\'[999:9999] result in error? Since \'example\'[9] does, what is the motivation behind it?

From this behavior I can a

3条回答
  •  故里飘歌
    2020-11-22 03:21

    Slicing is not bounds-checked by the built-in types. And although both of your examples appear to have the same result, they work differently; try them with a list instead.

提交回复
热议问题