Python Lambda Function

Say we have a value which is unknown..

So in general scenario we declare an unknown expression to a known and find the number or value.

So the same takes place lambda is an unknown expression to which we are going to declare a known value and find the value of lambda..

Lambda function can take a set of arguments but to only one expression.

lambda function

Now let us illustrate this concept with an example.

general syntax: lambda arguments: expression

code:

x = lambda a:  a + 19
print(x(5))

What did I code here?

It is a code where I’m trying to pass an argument where it is going to add 5 to my passed argument..

Let us see the output:

Let us now take a some set of values and understand this concept much more deeply.

x = lambda a, b, c: a + b + c
print(x(5, 7, 9))

Now let us try to declare a function inside another function and implement the coding.

General structure:

def mypy(x) #mypy- function

return lambda a : a*x

Code:

def mypy(x)
return lambda a : a/n
mynum = mypy(2) #declaring a divisor
print(mypy(4) ##declaring the dividend

Scroll to top