What is a negative index in python?



What is a negative index in python?..

Answer / chaitanya

Python arrays & list items can be accessed with positive or negative numbers (also known as index).

For instance our array/list is of size n, then for positive index 0 is the first index, 1 second, last index will be n-1. For negative index, -n is the first index, -(n-1) second, last negative index will be – 1.

A negative index accesses elements from the end of the list counting backwards.

An example to show negative index in python

>>> import array

>>> a= [1, 2, 3]

>>> print a[-3]

1

>>> print a[-2]

2

>>> print a[-1]

3

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

Mention the use of // operator in Python?

0 Answers  


Explain about assertions in python?

0 Answers  


Is there a switch or case statements in python?if not what is the reason for the same?

0 Answers  


What are the 3 types of loops?

0 Answers  


What is sphinx python?

0 Answers  


How to find the index of an element in a list python?

0 Answers  


Is python is a case sensitive?

0 Answers  


How do you use super in python?

0 Answers  


What are membership?

0 Answers  


How is python different from java?

0 Answers  


Is there a benefit to using one over the other?

0 Answers  


What is the difference between remove() function and del statement?

0 Answers  


Categories