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 →
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 elements treated as a single composite value or record.
- tuple unpackingused by · Tuple unpacking is assigning the elements of an iterable to multiple corresponding targets in a single operation.
- collectused by · collect is an operation that consumes produced values and gathers them into a collection or other result.
- indexingproduces · Indexing is the organization or use of positions, keys, or lookup structures to identify and retrieve selected data or elements.
- iteratoruses · An iterator is an object or abstraction that provides successive values from a sequence or data source through a traversal protocol.
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.


