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 |
Is python is intended oriented?
Do I need to learn c++ before python?
What are the types of literals in Python?
What is negative index in Python?
Does python has private keyword in python ? How to make any variable private in python ?
List out standard datatypes in python
How do you sort in descending order in python?
What exactly is SVM?
What is special about python?
List some namespace in python?
Is python interpreted or compiled?
What is python orm?