Slicing never raise error in python for out of bound indexes..
>>> s =[1,2,3]
>>> s[-1000:1000]
[1, 2, 3]
From the docs on string(applies to lists, tuples as well):
Degenerate slice indices are handled gracefully: an index that is too
large is replaced by the string size, an upper bound smaller than the
lower bound returns an empty string.
Docs(lists):
The slice of s
from i
to j
is defined as the sequence of items with
index k
such that i <= k < j
. If i
or j
is greater than len(s)
, use
len(s)
. If i
is omitted or None
, use 0
. If j
is omitted or None
, use
len(s)
. If i
is greater than or equal to j
, the slice is empty.
Out-of-range negative slice indices are truncated, but don’t try this for single-element (non-slice) indices:
>>> word = 'HelpA'
>>> word[-100:]
'HelpA'