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 will you convert an integer to a hexadecimal string in python?
is there any maximum length expected for an identifier?
How will you get all the keys from the dictionary?
Write a regular expression that will accept an email id. Use the re module.
What does making the cpython different from python?
How to split a string into a list?
What is __init__.py for?
What is the os module?
How do I stop a python script?
What are the difference between python and java?
How to convert a string to lowercase in Python?
What are magic methods in python?