Function which doesn’t contain any name explicitly is known as lambda functions or anonymous functions.
syntax:
lambda argument:expression
lambda function can contain 'n' number of arguments.
lambda function can contain only one expression.
After executing lambda function it will returns the expression value.
Ex:
double=lambda x:x*x
print(double(5))
Generally we use the lambda functions when ever we want to pass one function as parameters to another function
syntax:
lambda argument:expression
lambda function can contain 'n' number of arguments.
lambda function can contain only one expression.
After executing lambda function it will returns the expression value.
Ex:
double=lambda x:x*x
print(double(5))
Generally we use the lambda functions when ever we want to pass one function as parameters to another function
Ex:
my_list=[1,2,3,5,6,8]
even_list=filter(lambda x:(x%2==0),my_list)
odd_list=filter(lambda x:(x%2!=0),my_list)
print(even_list)
print(odd_list)
For Complete Python Training in Gwalior

No comments:
Post a Comment