Files
org_roam/Notes/20250805143741-python_lambda.org
Zaine Arch 74449c345a
All checks were successful
Build Roam Site / build (push) Successful in 30s
commits
2026-05-13 22:48:34 +01:00

745 B

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