Sitemap
Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Enumerate in Python

2 min readNov 25, 2024

--

Press enter or click to view image in full size

The enumerate() function in Python is a built-in utility that allows you to loop over an iterable (like a list, tuple, or string) and get the index and value of each item simultaneously. It is commonly used in for-loops.

Read the full story here: https://allwin-raju-12.medium.com/enumerate-in-python-8a61ce5a34fe?sk=461b686b96ab577d16707209d90767d3

Syntax:

enumerate(iterable, start=0)
  • iterable: The sequence you want to enumerate.
  • start: The starting value of the index (default is 0).

Returns:

An enumerate object, which produces pairs containing an index and the corresponding item from the iterable.

Example Usage:

1. Basic Example with List:

fruits = ['apple', 'banana', 'cherry']
for index, fruit in enumerate(fruits):
print(index, fruit)

Output:

0 apple
1 banana
2 cherry

2. Custom Start Index:

for index, fruit in enumerate(fruits, start=1):
print(index, fruit)

Output:

1 apple
2 banana
3 cherry

3. Using enumerate() with a Tuple:

--

--

Python in Plain English
Python in Plain English

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.