Zachary Ware <[email protected]> added the comment:
`-1` is not out of bounds unless the array is empty; negative indices count
from the other end:
>>> a = list("some array")
>>> a
['s', 'o', 'm', 'e', ' ', 'a', 'r', 'r', 'a', 'y']
>>> a[-1]
'y'
>>> b = []
>>> b[-1]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
IndexError: list index out of range
See about halfway down this [1] section; look for "Indices may also be
negative".
[1]
https://docs.python.org/3/tutorial/introduction.html?highlight=Indices+negative+numbers#strings
----------
nosy: +zach.ware
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue39095>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com