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
Should I learn r or python first?
How do you append to a file?
How to convert string into datetime?
How can you create a gui based application in python for client-side functionality?
How do I run a python script in windows 10?
What is a python module?
What is flask (__ name __)?
You are having multiple memcache servers running python, in which one of the memcacher server fails, and it has your data, will it ever try to get key data from that one failed server?
how do I pass a variable by reference?
What is anaconda program?
What is a flask?
How is numpy different from scipy?
What is flask- wtf? Explain its features.
What is range() in python?
What is the difference between python and shell scripting?