lambda
lambda — An anonymous function.
# Python code to illustrate cube of a number
# showing difference between def() and lambda().
def cube(y):
return y*y*y;
g = lambda x: x*x*x
print(g(7))
print(cube(5))
- inline function.
- Can have any number of arguments but only one expression, which is evaluated and returned.
- syntactically restricted to a single expression.
- Semantically, they are just syntactic sugar for a normal function definition.