Language Syntax
Lambda — Python syntax
Create a function whose body is a single expression and whose result is returned implicitly. Statements and parameter annotations are not allowed; defaults and closures work as with def.
Formal Syntax & Structure
python syntaxpython
lambda parameters: expressionParameters & Attributes
| Name | Type | Description |
|---|---|---|
| parameters | parameter list | Optional function parameters. |
| expression | expression | Single expression returned by the function. |
Return Value
function
Value obtained by evaluating this expression; see description for context and constraints.
Working Example
Example Snippetpython
items=['bbb','a','cc']print(sorted(items,key=lambda s: len(s)))