Python supports the creation of anonymous functions called lambda. It is often used in conjunction with functions like filter(), map() and reduce().
The general form of lambda’s are:
lambda arg1, arg2, ...argN : expression using arguments
Consider the following example of the function multiply():
def multiply(x, y):
return x * y
Because of the simplicity of the function we can convert it to a lambda function.
lambd = lambda x, y: x * y
To note here is, because lambda’s are also known as “throwaway functions”, it is ok to use _
as its “name”.