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?



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

Post New Answer

More Python Interview Questions

What if you want to toggle case for a python string?

0 Answers  


Explain the difference between local and global namespaces?

0 Answers  


What is the purpose of bytes() in python?

0 Answers  


How do you escape a string in python?

0 Answers  


Explain help() and dir() functions in python?

0 Answers  


What are python decorators? 8) What is the difference ...

0 Answers  


Explain the uses of the modules sqlite3, ctypes, pickle, traceback, and itertools.

0 Answers  


What is __ getitem __?

0 Answers  


Is python better than matlab?

0 Answers  


What is the purpose of “end” in python?

0 Answers  


How to get all keys from dictionary ?

0 Answers  


What are args and kwargs in Python?

1 Answers  


Categories