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 |
How to send a object and its value to the garbage collection?
Does python support database programming?
Is python numpy better than lists?
Can you remove the whitespaces from the string “aaa bbb ccc ddd eee”?
What is a decorator in python?
What is the incorrect declaration of a set?
How long do goats sleep?
What is python shell scripting?
Which software is best for python programming?
What is the length of your largest python code? Can you please describe the project?
Does python has private keyword in python ? How to make any variable private in python ?
What is the difference between encapsulation and abstraction in python?