Google News
logo
Python Program to A lambda function that multiplies argument a with argument b
In the following example of Python program to create a lambda function that multiplies argument a with argument b :
multiply = lambda a, b: a * b​

In this program, we have defined a lambda function named `multiply` that takes two arguments `a` and `b` and returns their multiplication. The `lambda` keyword is used to create the function, followed by the arguments `a` and `b`, separated by a comma.

The colon `:` is used to separate the arguments from the expression to be evaluated, which is `a * b` in this case.

We can then call this lambda function like any other regular function by passing the arguments :

Program :
multiply = lambda a, b: a * b
result = multiply(2, 5)
print(result)
Output :
10
Here, we are passing the arguments `2` and `5` to the `multiply` lambda function and storing the result in a variable named `result`.

The output will be `10`, which is the multiplication of `2` and `5`.