Use lambda to define simple function : lambda function « Function « Python






Use lambda to define simple function

Use lambda to define simple function

def make_incrementor (n): return lambda x: x + n
 
f = make_incrementor(2)
g = make_incrementor(6)
 
print f(42), g(42)

 
print make_incrementor(22)(33)



           
       








Related examples in the same category

1.lambda function definition with default valuelambda function definition with default value
2.Define function in Lambda FormsDefine function in Lambda Forms
3.Difference between a normal function and a lambda functionDifference between a normal function and a lambda function
4.Define lambda function inside another functionDefine lambda function inside another function