File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -1650,9 +1650,26 @@ Assignment expressions
16501650.. productionlist ::
16511651 assignment_expression: [`identifier ` ":="] `expression `
16521652
1653- .. TODO: BPO-39868
1653+ An assignment expression (sometimes also called a "named expression" or
1654+ "walrus") assigns an :token: `expression ` to an :token: `identifier `, while also
1655+ returning the value of the :token: `expression `.
16541656
1655- See :pep: `572 ` for more details about assignment expressions.
1657+ One common use case is when handling matched regular expressions:
1658+
1659+ .. code-block :: python
1660+
1661+ if matching := pattern.search(data):
1662+ do_something(matching)
1663+
1664+ Or, when processing a file stream in chunks:
1665+
1666+ .. code-block :: python
1667+
1668+ while chunk := file .read(9000 ):
1669+ process(chunk)
1670+
1671+ .. versionadded :: 3.8
1672+ See :pep: `572 ` for more details about assignment expressions.
16561673
16571674
16581675.. _if_expr :
You can’t perform that action at this time.
0 commit comments