Intellipaat Back

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

Can anyone explain map in Python with an example?

1 Answer

0 votes
by (119k points)

Map function returns the map object after applying the function on all the elements of the set of specified values stored in the iterables like 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]

If you are looking for the certification course, you can check out this Python Certification by Intellipaat.

Also, watch this video on Python:

Related questions

0 votes
1 answer
asked Jun 5, 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)
0 votes
1 answer
asked Sep 25, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jul 6, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...