What is lambda in Python? Why is it used?

By Poornima, 7 months ago
  • Bookmark
0

Explain lambda function in detail with example

Lambda fuction
1 Answer
0

Lambda function in Python 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
division = lambda x, y : x / y
print(division(12, 3))    # output => 4.0
  • Wrapping lambda functions inside another function
def wrapperfun(n):
  return lambda x : x * n

mulvalue = wrapperfun(8)
print(mulvalue(3))    # output => 24

Your Answer

Webinars

Live Masterclass on "Python for Artificial Intelligence"

Dec 4th (7:00 PM) 195 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More