1.

Lambda Function in Python

Answer»

These are small anonymous functions in python, which can take any number of arguments but returns only 1 expression.

Let us understand it with an example,

Consider the function which multiplies 2 numbers:

def mul(a, b):
return a * b
print(mul(3, 5))
Output:
15

The equivalent Lambda function for this function will be:

mul = lambda a, b: a * b
print(mul(3, 5))
Output:
15

The syntax for this will be as shown below:

Similarly, other functions can be written as Lambda functions too, resulting in shorter codes for the same program logic.




Discussion

No Comment Found