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]).

Answered by Samim E. Python tutor

2120 Views

See similar Python Mentoring tutors

Related Python Mentoring answers

All answers ▸

Write a program that takes a value x and then outputs x Fibonnaci numbers. E.g. if x=6 output would be 1 1 2 3 5 8


How might we implement the bubble sort algorithm in Python


Write a python function that takes a string as parameter and returns the character in the string with the most occurrences, along with the number of times this character occurs


Write a function s(n) that will return a list of the first n squares.


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy