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
Answered by Samim E. Python tutor

2608 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

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


How would you loop over every key and value in a python dictionary?


How would you write a while loop to print all even numbers from 1-10?


Write a simple Python program that asks a user to input their age and name and then return the text: "Hi my name is *NAME*, and I am *AGE* years old."


We're here to help

contact us iconContact ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences