Chapter 6. Expressions 80 The Python Language Reference, Release 3.9.5 6.12 Assignment expressions 6.13 Conditional expressions 6.14 Lambdas Lambda expressions (sometimes called lambda forms) are used to create anonymous functions. The expression lambda parameters: 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. def <lambda>(parameters): return expression conditional_expression ::= or_test ["if" or_test "else" expression ] expression ::= conditional_expression | lambda_expr Conditional expressions (sometimes called a “ternary operator”) have the lowest priority of all Python operations. The expression$_{x if C else y}$first evaluates the condition, C rather than x . If C is true, x is evaluated and its value is returned; otherwise, y is evaluated and its value is returned. See PEP 308 for more details about conditional expressions. New in version 3.8: See PEP 572 for more details about assignment expressions. while chunk :=file.read(9000 ): process(chunk) if matching :=pattern.search(data): do_something(matching) Or, when processing a file stream in chunks: One common use case is when handling matched regular expressions: An assignment expression (sometimes also called a “named expression” or “walrus”) assigns an expression to an identifier , while also returning the value of the expression . assignment_expression ::= [ identifier ":="] expression $_{lambda_expr}$::= "lambda" [ parameter_list ] ":" expression