Tutorial Study Image

Python enumerate()

The enumerate function takes an iterable, assigns an index for each item in the iterable, and returns an enumerated object.

enumerate(iterable,start) #Where iterable can be a list,string,tuple, dictionary,set etc

enumerate() Parameters:

An iterable is taken as the major input.An optional parameter start can be given to specify the starting index

Parameter Description Required / Optional
iterable A collection that supports iteration Required
start An integer. The enumeration starts with this parameter.
Default is 0

enumerate() Return Value

Each element in the iterable passed will be assigned a sequence index.

Input Return Value
Iterable, start returns an enumerated object and starts enumerating from start.

Examples of enumerate() method in Python

Example 1: Passing only the iterable

letters = ['a','b','c','d'] 
enumeratedList = enumerate(letters) 


Example 2: Specifying start and looping over enumerated object

letters = ['a','b','c','d']
enumeratedList = enumerate(letters,start=5) 
for count,each_letter in enumeratedList:


5 a
6 b
7 c
8 d