What is a negative index in python?

What is a negative index in python?

- 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
How do you make an array in Python?
How do you make an array in Python? - The array module contains methods for creating arrays of fixed types with homogeneous data types. Arrays are slower then list......
How to create a multidimensional list?
There are two ways in which Multidimensional list can be created: By direct initializing the list as shown below to create multidimlist below......
How to overload constructors (or methods) in Python
How to overload constructors (or methods) in Python - _init__ () is a first method defined in a class. when an instance of a class is created, python calls __init__() to initialize the attribute of the object.........
Post your comment