What is the use of negative indexing in the list?

Basically indexes used in array or list starts from indexing 0 in most of the programming languages.

But in Python, we have an extra feature of negative indexing. The negative indexing is the act of indexing from the end of the list with indexing starting at -1 i.e. -1 gives the last element of list, -2 gives the second last element of list and so on.

The use of negative indexing can be done to use or display data from the end of the list and can also be used to reverse a number or string without using other functions.

Python Source Code: Use of Negative Index


>>> msg = "Cat"
>>> msg[-1]
't'
>>> msg[-2]
'a'
>>> msg[-3]
'C'