## 6.12 Assignment expressions 

assignment_expression ::= [ identifier ":="] expression 

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 . 

One common use case is when handling matched regular expressions: 

if matching :=pattern.search(data): do_something(matching) 

Or, when processing a file stream in chunks: 

while chunk :=file.read(9000 ): process(chunk) 

New in version 3.8: See PEP 572 for more details about assignment expressions. 

## 6.13 Conditional expressions 

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. 

## 6.14 Lambdas 

$_{lambda_expr}$::= "lambda" [ parameter_list ] ":" expression 

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: 

def <lambda>(parameters): return expression 

See section Function definitions for the syntax of parameter lists. Note that functions created with lambda expressions cannot contain statements or annotations. 

