File tree 1 file changed +19
-2
lines changed
1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -1650,9 +1650,26 @@ Assignment expressions
1650
1650
.. productionlist ::
1651
1651
assignment_expression: [`identifier ` ":="] `expression `
1652
1652
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 `.
1654
1656
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.
1656
1673
1657
1674
1658
1675
.. _if_expr :
You can’t perform that action at this time.
0 commit comments