Why are negative indexes used?

They are used to access locations from last indexes of any array. So lets say you want to print last two items of an array you will write print(A[-2:]) or if you dont want to display last 3 items of the array you would write print(A[:-3]).

SE

Related Python Mentoring answers

All answers ▸

How could I write a program to convert Km/h to m/s in python


Write a simple number guessing game, give the user 3 tries to guess a number between 1 and 10


Explain how python programs are structured and give an example of how methods are initiated


Give an example of a FOR loop