What is anonymous function or lambda function in python?

Description

To see what is lambda function and syntax of lambda function in python3.

Anonymous or lambda function. 
  • Lambda functions are small functions
    usually not more than a line.
  • Its also called as one line function.
  • Lambda function can have any number
    of arguments but only one expression.
  • It defined with keyword lambda.
  • Its mostly used for mathematical
    expression 

#lambda function to double the input
d = lambda x: x * 2
print(“——First output——\n”)
print(d(6))

#lambda functions with mapping
list1=[2,8,6,3,7,5,4]
print(“——Second output——\n”)
newlist=list(map(lambda x: x * 2,list1))
print(newlist)

Leave Comment

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

clear formSubmit