Python Lambda Function with Example
Lambda Function or Anonymous Functions are throw-away functions, they are just needed where they have been created and it can be used anywhere a function is required. It’s just created by using lambda keyword. It has the following syntax:
lambda arguments: expression
Properties of Lambda Function:
1. Lambda Functions have no name.
2. Lambda Function can take any number of arguments.
3. Lambda Function can return just one value in the form of an expression.
4. It doesn’t have an explicit return statement but it always contains an expression that is returned.
5. They can’t access variables other than those in their parameter list.
6. Lambda Function can’t even access global variables.
sum=lambda a, b: a+b print("The addition is:", sum(15, 10)
The addition is: 25
def small(x,y): if(x<y): return x else: return y sum=lambda x, y:x+y diff=lambda x, y:x-y print("The smaller of two number is=", small(sum(-3,-2), diff(-1,2)))
The smaller of two number is= -5