Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (55.6k points)

Can anyone explain the map function in python?

1 Answer

0 votes
by (119k points)
edited by

Map function returns the map object after applying the function on all the elements of the set of values stored in the list, tuple, etc.

Syntax:

Map (function, list or tuple)

Example:

# Return square of n

def addition(n):

                return n*n

  

# We double all numbers using map()

numbers = (1, 2, 3, 4)

result = map(addition, numbers)

print(list(result))

Output:

[1, 4, 9, 16] 

You can check out this Python Functions to learn more about map function with examples.

Also, watch this video on Python Functions:

Related questions

0 votes
1 answer
0 votes
3 answers
asked Sep 20, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jun 17, 2020 in Python by Sudhir_1997 (55.6k points)
0 votes
4 answers
0 votes
1 answer
asked Dec 17, 2020 in Python by ashely (50.2k points)

Browse Categories

...