lambda 為 Python 的關鍵字 (keyword) 之一,用來建立無名函數 (anonymous function) 。
https://docs.python.org/3/reference/expressions.html#lambda
lambda_expr ::= "lambda" [parameter_list
]:expression
lambda_expr_nocond ::= "lambda" [parameter_list
]:expression_nocond
Lambda expressions (sometimes called lambda forms) are used to create anonymous functions. The expression
lambda arguments:expression
yields a function object. The unnamed object behaves like a function object defined with
See section Function definitions for the syntax of parameter lists. Note that functions created with lambda expressions cannot contain statements or annotations.
範例:
f
=
lambda
x: x
*
*
x
雷同
def f(x):
return x**x
多變數用法
g
=
lambda
x, y: x
*
y
沒有留言:
張貼留言