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 ▸

Make a program that asks the user for a series of numbers until they either want to output the average or quit the program.


Implement a rocket launch countdown.


Create an algorithm that can be used as a guessing game. Make sure to import random at the start.


What is the outcome of the following code? print(2*[3,4,5])