Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

map()

Lazily calls a function with one successive item from each input iterable.

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

Syntax

map(function, iterable, /, *iterables, strict=False)

Lazily calls a function with one successive item from each input iterable.

The default stops at the shortest input. Strict mode in Python 3.14 raises ValueError for mismatched lengths.

A pull supplies one item from each input to the function as positional arguments. Only pow(2, 4) can be formed before the shorter input ends, giving 16. With strict=True, added in 3.14, the mismatch raises ValueError during consumption. Equal-length inputs finish normally.

it = map(pow, [2, 3], [4], strict=True)
assert next(it) == 16
try:
    next(it)
except ValueError:
    pass
else:
    raise AssertionError

Examples

print(list(map(pow, [2, 3], [4])))
try:
    list(map(pow, [2, 3], [4], strict=True))
except ValueError as error:
    print(type(error).__name__)

Result

[16]
ValueError

A pull supplies one item from each input to the function as positional arguments. Only pow(2, 4) can be formed before the shorter input ends, giving 16. With strict=True, added in 3.14, the mismatch raises ValueError during consumption. Equal-length inputs finish normally.

Sources