DP_
0
Q:

python anonymous function

Lamda is just one line anonymous function
Useful when writing function inside function
it can take multiple arguments but computes only one expression

Syntax:
   x = lambda arguments : expression
5
# You have to save the lambda expresion for it to work

nameOfLambda = lambda arg1, arg2: expression
2

lambda arguments : expression
7
def myfunc(n):
  return lambda a : a * n
mytripler = myfunc(3)
print(mytripler(11)) 
5

New to Communities?

Join the community