Files
org_roam/20250805143741-python_lambda.org
2026-03-08 13:04:05 +00:00

745 B
Executable File

python-lambda

A lambda function is a small anonymous function.

A lambda function can take any number of arguments, but can only have one expression.

Syntax:

lambda arguments : expression

The expression is executed and the result is returned:

  # Add 10 to argument a, and return the result:
  x = lambda a : a + 10
  print(x(5))

  # Multiply argument a with argument b and return the result:
  y = lambda a, b : a * b
  print(y(5, 6)) 

  # Summarize argument a, b, and c and return the result:
  z = lambda a, b, c : a + b + c
  print(z(5, 6, 2))
15
30
13