lambda

lambda — An anonymous function.

a = lambda x,y : x+y
print(a(5, 6))
# 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.

Related concepts

lambda — Structure map

Clickable & Draggable!

lambda — Related pages: