Python map() function
Published February 16, 2022The map() function is a built-in function that lets you work with and change iterable objects without using the explicit for loop. When using map(), you apply this method to each item in the specified iterable, which may be a tuple, a list, etc., and obtain an iterator or map object as a result.
A map() loops over an iterable and applies a function to each item, returning a new iterator containing the modified objects.
Syntax
The map() function is implemented using the simple syntax shown below.
map(function, iterable) |
where:
function: A function that will be called for each iterable element.
iterable: the iterable to be mapped
Let's look at an example to see how map() works in more detail:
Example
def sum(a): |
Output
[12, 14, 18, 16, 8, 10] |
Article Contributed By :
|
|
|
|
336 Views |