I\'m curious about the difference between lambda
function and a regular function (defined with def
) - in the python level. (I know what is the diff
Lambda is an inline function where we can do any functionality without a function name. It is helpful when we use it as an argument to a higher-order function. Eg: A function that takes in other functions as arguments.
Example of Function definition:
>>> def func(a, b):
return a * b
>>> func(2,3)
6
>>> type(func)
>>> func
Example of Lambda expression:
>>> multiply = lambda a, b: a * b
>>> multiply(2, 3)
6
>>> type(multiply)
>>> multiply
at 0x034B6ED0>
Both returns same output value. Only object returned are different. "func" name for Function and for Lambda.