0 votes
in Python Flask by
What are negative indices?

1 Answer

0 votes
by
Let’s take a list for this.

>>> mylist=[0,1,2,3,4,5,6,7,8]
A negative index, unlike a positive one, begins searching from the right.

>>> mylist[-3]
6

This also helps with slicing from the back:

>>> mylist[-6:-1]
[3, 4, 5, 6, 7]
...