Lambda Expressions
The lambda operator or lambda function is a way to create small anonymous functions, i.e. functions without a name. These functions are throw-away functions, i.e. they are just needed where they have been created.
Lambda functions are mainly used in combination with the functions filter(), map() and reduce()(reduce() is no more supported in Python 3.x).
The general syntax of a lambda function is quite simple: lambda <argument_list> : <expression>
The argument list consists of a comma separated list of arguments and the expression is an arithmetic expression using these arguments.
The following example of a lambda function returns the sum of its two arguments:
sum = lambda x,y : x + y
sum(3,4)
We could have had the same effect by just using the following conventional function definition:
def sum(x,y):
return x+y
sum(3,4)