Built-in Functions and Types

zip()

Walk iterables together, yielding one tuple per round. By default the first exhausted input stops the result, possibly hiding unequal input lengths. Use strict=True when lengths must agree; mismatch is discovered while consuming the iterator, not generally at construction. With no inputs it yields nothing; a single input produces one-item tuples. Inputs are advanced in left-to-right order and a mismatched traversal may consume an extra item.

Formal Syntax & Structure

python syntaxpython
zip(*iterables, strict=False)

Parameters & Attributes

NameTypeDescription
iterableszero or more iterablesSources traversed in parallel.
strictboolKeyword-only; raise ValueError on unequal lengths.

Return Value

zip iterator

Single-pass iterator yielding tuples of aligned items.

Working Example

Example Snippetpython
names = ["Ada", "Sam"]scores = [9, 7]print(list(zip(names, scores, strict=True)))print(dict(zip(names, scores)))
Python Reference