0% found this document useful (0 votes)
21 views

What Is Lambda in Python? Why Is It Used?

Lambda is an anonymous function in Python that can accept multiple arguments but only return a single expression. It is commonly used when an anonymous function is needed for a short time, such as assigning it to a variable or wrapping it inside another function. Lambdas allow defining simple anonymous functions inline without needing to define a separate function with a name.

Uploaded by

ameetamarwadi
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

What Is Lambda in Python? Why Is It Used?

Lambda is an anonymous function in Python that can accept multiple arguments but only return a single expression. It is commonly used when an anonymous function is needed for a short time, such as assigning it to a variable or wrapping it inside another function. Lambdas allow defining simple anonymous functions inline without needing to define a separate function with a name.

Uploaded by

ameetamarwadi
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

What is lambda in Python? Why is it used?

Lambda is an anonymous function in Python, that can accept any number of arguments, but
can only have a single expression. It is generally used in situations requiring an anonymous
function for a short time period. Lambda functions can be used in either of the two ways:
• Assigning lambda functions to a variable
mul = lambda a, b : a * b
print(mul(2, 5)) # output => 10
• Wrapping lambda functions inside another function
def myWrapper(n):
return lambda a : a * n

mulFive = myWrapper(5)
print(mulFive(2)) # output => 10

You might also like