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 ▸

Write a basic program to output the lowest of 3 input numbers. (You may omit error checks on your inputs)


What is the difference between a float and an integer variable type?


Write a function that checks whether a number is prime or not.


How do I check if a number is prime using a python program?