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 ▸

Explain how you would write a python program that takes a rectangle and a point in a 2D space as command-line arguments and checks if they intersect.


Implement a fibonacci function which calculates the nth number of the fibonacci sequence.


[Student query] Why do we import libraries/modules such as Numpy and Matplotlib into Python?


Create a program that takes in two numbers and returns the highest of the two