Table of Contents
Definition and Usage
The map() function executes a specified function for each item in an iterable. The item is sent to the function as a parameter.
Python map() function
map() function returns a map object(which is an iterator) of the results after applying the given function to each item of a given iterable (list, tuple etc.)
Syntax:
Parameter
- fun :Â It is a function to which map passes each element of given iterable.
- iter :Â It is a iterable which is to be mapped.
NOTE :Â You can pass one or more iterable to the map() function.
Returns :
NOTE : The returned value from map() (map object) then can be passed to functions like list() (to create a list), set() (to create a set) .
Example 1:
Output:
Example 2:
Output:
Example 3:
Output: