Sunday, August 2, 2015

What is Enumerate?

Enumerate is a built-in function which return a enumerate object which consists of tuple containing a count (from start which defaults to 0) and the values obtained from iterating over sequence. In simple terms it add counter to the sequence.

>>> fruits = ['Banana', 'Apple', 'Lime']
>>> for item in enumerate(fruits):
        print(item)
(0,'BANANA')
(1,'APPLE')
(2,'LIME')

It is used to get the values printed along with indexes. 
5 Python: What is Enumerate? Enumerate is a built-in function which return a enumerate object which consists of  tuple containing a count  (from  start  which defaults...

No comments :

Post a Comment