Lambda Functions

 Lambda Functions in Python are anonymous functions, implying they don't have a name. The def keyword is needed to create a typical function in Python, as we already know. We can also use the lambda keyword in Python to define an unnamed function.


lambda arguments: expression


Code:

# Code to demonstrate how we can use a lambda function  

add = lambda num: num + 4  

print( add(6) )  


Output:

10


The lambda function is "lambda num: num+4" in the given programme. The parameter is num, and the computed and returned equation is num * 4.

There is no label for this function. It generates a function object associated with the "add" identifier. We can now refer to it as a standard function. The lambda statement, "lambda num: num+4", is nearly the same as:


Code:

def add( num ):  

   return num + 4  

print( add(6) )  


Output:

10