Anonymous functions or lambdas

 

The function without any name is called anonymous function. So we write anonymous function def keyword is not used. These functions are defined with keyword lambdas so they are also called lambdas.

The lambda keyword represents the anonymous function and the : represents function has been started.

Syntax:

lambda argument_list: expression

lambda returns function so it assign to function. In following example fun is function.

Example:

fun=lambda x : x*x*x

ans=fun(5)

print("Cube is",ans)

Output:

('Cube is', 125)

'''Anonymous functions or lambdas'''

fun=lambda x,y:x+y

ans=fun(5,6)

print("sum is",ans)

Output:

('sum is', 11)