In Python, enumerate(iterable, start=0) returns an iterator of (index, item) pairs: (0, first), (1, second), and so on. It is the Pythonic replacement for range(len(items)) when a loop needs both the position and the value.
The optional start sets the first counter value, for example 1 for human-friendly numbering. The result is lazy like zip() and map(); wrap it in list() or dict() to see all pairs at once.
enumerate is a built-in type (a class) that you call like a function: each call creates a new enumerate object. Like every built-in, it lives in the builtins module and is always available without an import.
Syntax
Unpack the pair directly in the for statement.
python
for index, item in enumerate(items):
...
for number, item in enumerate(items, start=1):
...
Call
What it does
enumerate(["a", "b"])
Yields (0, 'a'), (1, 'b').
enumerate(items, 1)
Counting starts at 1.
list(enumerate("hi"))
Returns [(0, 'h'), (1, 'i')].
dict(enumerate(seq))
Maps each index to its item.
start only changes the numbers you see; it does not skip items.
Library declarations
python
enumerate(iterable, start=0)
# class enumerate: returns an iterator of (count, item) tuples
Parameters
Parameter
Description
iterable
Required. Any iterable.
start
Optional. The first count value. Default 0.
Return Value
Return Value
Description
enumerate
An iterator of (count, item) tuples.
Python Examples
Example 1 — Loop with an Index
Print each fruit with its index, then list the pairs with a custom start.
python
fruits = ["apple", "banana", "cherry"]
for index, fruit in enumerate(fruits):
print(index, fruit)
print(list(enumerate(fruits, start=1)))
Pairs. Each step yields a tuple like (0, 'apple').
Unpacked in the loop.for index, fruit in ... splits the tuple into two names.
Zero-based by default. The counter matches list indexes: 0, 1, 2.
Custom start.start=1 shifts the numbers to 1, 2, 3.
Example 2 — Numbered Output and Positions of a Character
Print a 1-based task list and collect the positions of a letter.
python
tasks = ["write tests", "fix bug", "deploy"]
for number, task in enumerate(tasks, 1):
print(f"{number}. {task}")
text = "banana"
positions = [i for i, ch in enumerate(text) if ch == "a"]
print("'a' found at", positions)
Output
1. write tests
2. fix bug
3. deploy
'a' found at [1, 3, 5]
How It Works
Human numbering. Passing 1 as the second argument gives a list that starts at 1.
Any iterable. Strings work too; each step yields an index and a character.
Filter positions. The comprehension keeps the index whenever the character is "a".
No manual counter. There is no i = 0 and i += 1 to get wrong.
Example 3 — Update Items by Index and Build Lookups
Raise low scores in place, find empty lines, and turn an enumeration into a dict.
python
scores = [55, 91, 47, 78]
for i, score in enumerate(scores):
if score < 60:
scores[i] = 60
print(scores)
lines = ["first", "", "third"]
empty = [n for n, line in enumerate(lines, start=1) if not line]
print("empty line numbers:", empty)
lookup = dict(enumerate("xyz"))
print(lookup)