Showing posts with label map () python function.function in python. Show all posts
Showing posts with label map () python function.function in python. Show all posts

Tuesday, December 1, 2020

,

Example program for map() function in python

 map() function in Python applies a given function to every item of an iterable and give a list of results.

Syntax:-

map(function, iterable, ...)

Parameter For map() function in python 

map() function use two Parameter these are follow : - 

  •  function is a first Parameter map() function passes every item of iterable to the given function.
  • iterables are second which is going to to be mapped.

 Return value : - map() function in python return the list of result.

Example of map() function in python

def calculateSquare(n):
    return n*n


numbers = (1, 2, 3, 4)
result = map(calculateSquare, numbers)
print(result)

# converting map object to set
numbersSquare = set(result)
print(numbersSquare)

OUTPUT : -

map() function output
 map() function output

Well Python lambda Function commonly used with map () python function.