All Courses

What is lambda in Python? Why is it used?

By Poornima, 2 years 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 : "How Machine Get Trained in Machine Learning?"

Jun 1st (5:32 PM) 515 Registered
More webinars

Related Discussions

Running random forest algorithm with one variable

View More