Language Syntax

Assignment expression — Python syntax

Bind a single identifier and yield the assigned value within an expression. Parentheses are required in some contexts; this is not a replacement for unpacking or attribute assignment.

Formal Syntax & Structure

python syntaxpython
(name := expression)

Parameters & Attributes

NameTypeDescription
nameidentifierName to bind.
expressionexpressionValue to bind and yield.

Return Value

object

Value obtained by evaluating this expression; see description for context and constraints.

Working Example

Example Snippetpython
values = [1, 2, 3]print(((n := len(values)), n))
Python Reference