Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is a negative index in python?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is upper in python?

742


Which version of python is best?

824


Which methods/functions do we use to determine the type of instance and inheritance?

775


Are sets hashable python?

777


Tell me how do you debug a program in python? Is it possible to step through python code?

753


How to test multiple variables against a value?

894


What is a closure in python?

831


What are string literals in python?

907


Name few python checkers for debugging?

817


What is module and package in Python?

899


Why do we want to use break statement in while-loop?

752


What is kwargs in python?

810


What is the purpose of the pythonstartup environment variable?

788


What is called loop?

811


Explain the five benefits of using python?

860