How map method can be used in Python program

The map() function applies a given function to each item of an iterable (list, tuple etc.) and returns a list of the results.
Syntax:​ map(function, iterable, …)
map() Parameter:
function – map() passes each item of the iterable to this function. iterable iterable which is to be mapped

def calculateSquare(n):
return n*n

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

numbersSquare = set(result) 

<map object at 0x7f722da129e8> 
{16, 1, 4, 9}

To Learn more about Python, Click Here

Click here To Follow on pinterest

Leave a Comment

Your email address will not be published. Required fields are marked *