Sunday 25 December 2016

What is Enumerate in Python?

Enumerate  function is used to iterate through a list while keeping track of the list items' indices.
Syntax:enumerate(elements)
Example : x = ('A', 'B', 'C')
                 for i,y in enumerate(x):
                      print(i,x)
                Output: 0   A              #Indexing starts from 0 by Default  
                             1   B
                             2   C
             
Important:
1.By default enumerate counts from 0,but you could index it accordingly by providing 2nd argument.

Example:for i,y in enumerate(x,50): # 2nd argument value is set to 50
                      print(i,x)
                Output: 50   A                     #Indexing starts from 50 as it is given as argument in function
                             51   B
                             52   C















Bored of Learning ?Wanna go out on a tour(full of adventures,excitement) please visit www.desistreets.com .