Search your course

 

 

Python Lambda


A lambda function is a small anonymous function.

A lambda function can take any number of arguments, but can only have one expression, After execution of script result is returned.

Following are some examples of Lambda expression

 

x = lambda a : a + 20
print(x(10)) 

It will print out 20 as a result.

Lambda Expression can take as many arguments as you wish

 

x = lambda a,b,c : a*b+c
print(x(10,4,5)) 

It will print out 45

Now lets see how we can find greatest of two numbers using lambda

 

x = lambda a,b : a if a>b else b
print(x(15,10))

 

Subscribe to my youtube channel