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

What makes python object-oriented?

0 Answers  


How to avoid having class data shared among instances in python?

0 Answers  


What is instance method?

0 Answers  


How will you remove an object from a list?

0 Answers  


Do you know how python is interpreted?

0 Answers  






Explain about python’s parameter passing mechanism?

0 Answers  


Why should I learn python in 2019?

0 Answers  


What language is python based on?

0 Answers  


Is Python good for backend?

0 Answers  


How are phon blocks defined?

0 Answers  


What is the best tutorial for python?

0 Answers  


What is the purpose of the pythonpath environment variable?

0 Answers  


Categories