Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

enumerate()

Pairs successive input items with an incrementing counter.

Version: Python 3.14; repository image, production runtime not attested

Syntax

enumerate(iterable, start=0)

Pairs successive input items with an incrementing counter.

The start value changes the counter labels without skipping items in the underlying iterable.

The iterator yields a counter and an unchanged input item as a pair, beginning at zero by default. Starting at five labels a with 5 and b with 6 without skipping input. A counter alone cannot produce a row, so enumerating an empty collection produces no pairs.

it = enumerate(iter(["a", "b"]), start=-1)
assert next(it) == (-1, "a") and next(it) == (0, "b")

Examples

print(list(enumerate("ab", start=5)))
print(list(enumerate([], start=5)))

Result

[(5, 'a'), (6, 'b')]
[]

The iterator yields a counter and an unchanged input item as a pair, beginning at zero by default. Starting at five labels a with 5 and b with 6 without skipping input. A counter alone cannot produce a row, so enumerating an empty collection produces no pairs.

Sources