map() Map function
Last updated: 2026-09-22
map() Map function
map(function, iterable, ...) applies function to each item; returns an iterator.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
map(function, *iterables)
⚙️ Parameters
| function Required | A callable applied to each item. |
|---|---|
| iterables Optional | One or more iterables (variadic); function must accept that many arguments. |
Returns:A map iterator yielding function applied to each item.
💥 Raises
TypeError— Raised when function is not callable or an argument is not iterable.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
[1, 4, 9]
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QDoes map() return a list?
ANo, it returns a lazy map iterator; you need list(map(...)) to turn it into a list you can view or reuse directly.
QHow is func called when map(func, a, b) receives two lists?
Afunc takes one element from each list as arguments each time: list(map(lambda x, y: x + y, [1, 2], [3, 4])) gives [4, 6], truncating at the shortest list.
QWhich is better: map() or a list comprehension?
AFor simple logic a comprehension [f(x) for x in lst] is more readable; map combines more concisely with existing functions (e.g. map(str.upper, words)). Their performance is similar.
QDoes map execute immediately?
ANo, it is lazy — function is called one by one as iteration begins. For chained processing of large data this saves memory.