Python enumerate() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Built-in type

Definition

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):
    ...
CallWhat 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

ParameterDescription
iterableRequired. Any iterable.
startOptional. The first count value. Default 0.

Return Value

Return ValueDescription
enumerateAn 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)))

How It Works

  1. Pairs. Each step yields a tuple like (0, 'apple').
  2. Unpacked in the loop. for index, fruit in ... splits the tuple into two names.
  3. Zero-based by default. The counter matches list indexes: 0, 1, 2.
  4. 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)

How It Works

  1. Human numbering. Passing 1 as the second argument gives a list that starts at 1.
  2. Any iterable. Strings work too; each step yields an index and a character.
  3. Filter positions. The comprehension keeps the index whenever the character is "a".
  4. 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)

How It Works

  1. Write back by index. The index lets the loop replace items in the list it is reading.
  2. Line numbers. With start=1, the empty second line is reported as line 2.
  3. Truthiness test. not line is True only for the empty string.
  4. Index lookup. dict(enumerate("xyz")) maps 0, 1, 2 to the letters.

Frequently Asked Questions

Use enumerate: for i, item in enumerate(items). It yields the index and the item together.
Pass start=1 or just 1 as the second argument: enumerate(items, 1).
Yes, for most loops. It is shorter, works with any iterable, and avoids separate indexing.
enumerate returns a lazy iterator. Use list(enumerate(x)) to see the pairs.
Combine with zip: for i, (a, b) in enumerate(zip(xs, ys)).

Next: eval()

Evaluate a string as a Python expression.

eval() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful