Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Function

enumerate

enumerate() pairs each item from an iterable with an incrementing count. The count starts at 0 by default or at the supplied start value.

How it works

Call enumerate() with an iterable to obtain a lazy iterator of pairs. Each pair contains a counter and the next value from the iterable; the counter begins at start, which defaults to 0, and advances as iteration proceeds.

Syntax

enumerate(iterable, start=0)

Parameters

NameTypeDescription
iterableiterableObject to iterate over; it must support iteration.
startintegerInitial counter value; defaults to 0.

Returns

An enumerate object whose iterator yields tuples containing a count and each value from iterable.

Key points

  • The function returns an enumerate object rather than a materialized list.
  • Its input can be any object that supports iteration, including sequences and iterators.
  • Each produced element is a tuple whose first component is the current count.
  • Counting starts at the supplied start value, or at zero when start is omitted.
  • The second tuple component is the next value obtained from the input iterable.

Common mistakes

  • The first argument must be iterable; passing a non-iterable object raises a TypeError.

Example: Enumerate items with positions

items = ["alpha", "beta", "gamma"]
for index, item in enumerate(items, start=1):
    print(f"{index}: {item}")

Print each item together with a one-based position.

When to use it

Indexed iteration

Need both a position and a value while looping over a sequence.

One-based numbering

Display user-facing positions that begin at one instead of zero.

Counting streamed values

Process a generator while retaining the number of items seen.

Interview questions

QWhat does enumerate() return?

enumerate() returns an enumerate object, which is an iterator that yields tuples. Each tuple contains the current count and the corresponding value from the iterable.

Follow-up: What is the default first index? It is 0, unless a different start value is supplied.

QHow does the start argument work?

The start argument sets the initial count and defaults to 0. For example, start=1 produces counts beginning at 1 while leaving the iterable's values unchanged.

Follow-up: Can start be negative? Yes; it is used as the initial count, so negative values produce negative initial indices.

QWhat kinds of objects can enumerate() process?

enumerate() accepts a sequence, an iterator, or another object that supports iteration. It advances through that object and yields one count-value tuple per item.

Follow-up: What happens with a generator? enumerate() consumes it lazily as the returned iterator is advanced.

  • iter()
  • next()
  • zip()
  • range()

Source: Built-in Functions. Checked 2026-10-15.