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
fromi
toj
is defined as the sequence of items with indexk
such thati <= k < j
. Ifi
orj
is greater thanlen(s)
, uselen(s)
. Ifi
is omitted orNone
, use0
. Ifj
is omitted orNone
, uselen(s)
. Ifi
is greater than or equal toj
, 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'