Answer Posted / 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 View All Answers
Can a constructor be inherited?
Is django an ide?
What is meta class in python?
What is flask?
What is __init__.py used for?
What is sub() function?
What is mro in python?
Why are we using self as first argument?
What is a static relationship?
What is the difference between = and == in python?
What are differences between list and dictionary in python?
What are python’s dictionaries?
How to write a text from from another text file in python ?
Explain how you can minimize the memcached server outages in your python development?
What is python easy_install?