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

Which module(s) of python can be used to measure the performance of your application code?

0 Answers  


Why don’t python lambda have any statement?

0 Answers  


Why is self used in python?

0 Answers  


Whenever python exists why does all the memory is not de-allocated / freed when python exits?

0 Answers  


How to create an empty class in python?

0 Answers  






What is long in python?

0 Answers  


Write the command to get all keys from the dictionary.

0 Answers  


What program to write python?

0 Answers  


What is python’s standard way of identifying a block of code?

0 Answers  


What is abs in python?

0 Answers  


What is a function in python programming?

0 Answers  


What is map, filter and reduce in python?

0 Answers  


Categories