1.

What is a map() function in Python?

Answer»
  • In Python, the map() function is useful for applying the given function on every element of a specified iterable(list, tuple, etc.).
  • SYNTAX for map() function is: map(func, itr)
    Where func is a function applied to every element of an iterable and itr is iterable which is to be mapped. An object list will be RETURNED as a result of map() function execution.
  • Example:
def addition(n): return n+nnumber=(10, 20, 30, 40)res= map(addition, number)print(list(res))

Output: 20, 40, 60, 80

In the above code segment, we are passing the addition() function and number as parameters to the map() function. Now, the addition() function will be applied to every element of the number tuple, each ITEM value is ADDED with the same item value and the result generated will be stored in the res list.



Discussion

No Comment Found