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 create an empty class in python?
What is a generator in python?
What is python easy?
What are the two ways to use python interpreter?
Tell me what is dict and list comprehensions are?
Tell me what is the command to debug a python program?
What are different ways to create an empty numpy array in python?
Do while loops python?
Tell me the use of // operator in python?
What are the rules for local and global variables in Python?
How is numpy different from scipy?
Tell me what are generators in python?