Enumerate
enumerate is an iteration utility that yields pairs containing sequential indices and corresponding items from an iterable, optionally starting at a specified index.
Python How-To
The enumerate function is a Python built-in function that returns an iterator producing position-and-item pairs from an iterable.
- How it is used
- Improves for-loop iteration when each item must be displayed or processed with its position.
- How deep it goes
- Explains iterator creation, yielded tuples, default counters, start values, and tuple unpacking through worked loops.
- Examples
- Demonstrates numbered prime numbers and formatted task records using zero-based and one-based counters.
- What you can do after
- Apply it via Python's built-in enumerate function to write readable position-aware loops.
Python Workout, Second Edition
The enumerate function returns an iterator that yields pairs containing sequential indices and values from an iterable.
- How it is used
- Uses indexed iteration to solve loops that need positions alongside values, especially when processing strings.
- How deep it goes
- Explains returned pairs, unpacking, default indexing, and custom starts; connects iterator behavior to broader protocol study.
- Examples
- Demonstrates indexed alphabet output, hexadecimal digit processing, and alphabet-to-number dictionary construction.
- What you can do after
- Apply it via Python's built-in iterator to write concise loops and comprehensions that retain both positions and values.
Read how Python Workout, Second Edition explains enumerate →
Tiny Python Projects: Learn coding and testing with puzzles and games
enumerate() is a Python built-in function that produces pairs of indexes and values while iterating an iterable.
- How it is used
- Uses index-and-value iteration to format a Tic-Tac-Toe board and label empty cells.
- How deep it goes
- Defines returned pairs, default and custom starts, laziness, unpacking, and equivalent loop and comprehension forms.
- Examples
- Demonstrates board strings, REPL enumeration, numbered cells, and a tested format_board() function.
- What you can do after
- Apply it via Python to iterate values alongside positions and format indexed output.
Read how Tiny Python Projects: Learn coding and testing with puzzles and games explains enumerate →
Also covered in
- Rust in Action: Systems programming concepts and techniques
- Idiomatic Rust
- Learn Rust in a Month of Lunches
- Python Workout: 50 ten-minute exercises
- Julia as a Second Language
- The Quick Python Book, Fourth Edition
What to know first
- loopA loop is a programming-language control-flow construct that repeatedly executes a block of instructions according to an iteration rule or continuation condition.
- iteratorAn iterator is an object or abstraction that provides successive values from a collection or other data source through a traversal interface.
- tupleA tuple is a finite, ordered collection of values grouped as a single composite value, often with elements of different types.
- indexingIndexing is the process of assigning or using positions, keys, or lookup structures to identify and access elements or records.
Related concepts
- iterableuses · An iterable is an object or value that provides or supports a protocol for producing its elements sequentially.
- tupleproduces · A tuple is a finite, ordered collection of values grouped as a single composite value, often with elements of different types.
- collectused by · Collect is an operation that gathers produced values or records into a collection or other result.
- iteratoruses · An iterator is an object or abstraction that provides successive values from a collection or other data source through a traversal interface.
- indexingproduces · Indexing is the process of assigning or using positions, keys, or lookup structures to identify and access elements or records.
- tuple unpackingused by · Tuple unpacking is assigning the elements of an iterable to multiple corresponding targets in a single operation.
Questions about enumerate
What is enumerate?
enumerate is an iteration utility that yields pairs containing sequential indices and corresponding items from an iterable, optionally starting at a specified index.
Which Manning books explain enumerate?
Python How-To, Python Workout, Second Edition and Tiny Python Projects: Learn coding and testing with puzzles and games.
What should I know before learning enumerate?
Manning books that teach enumerate usually introduce loop, iterator, tuple and indexing first.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


