Negative indexing in Python

Negative indexes refer to the positions of elements within an array-like object such as a list, tuple, or string, counting from the end of the data structure rather than the beginning.

For example, in a list with 5 elements, the last element can be accessed using the index -1, the second to last element using the index -2, and so on. Negative indexes can be useful for accessing elements from the end of a data structure without having to know the exact length of the data structure.

Here is an example of a code that uses negative indexing to access the last and second last element of an array: