summaryrefslogtreecommitdiffstats
path: root/Lib/pydoc_data/topics.py
diff options
context:
space:
mode:
authorEmily Morehouse <emily@python.org>2024-09-27 20:59:26 (GMT)
committerGitHub <noreply@github.com>2024-09-27 20:59:26 (GMT)
commit626668912f3102a96d3f251f5304ad2f8326f3cc (patch)
treeb6de3e3db719f12f8dcd946697944e4bd93a596c /Lib/pydoc_data/topics.py
parent6cba6e1df2c20846347b705eff7fb28caeeb17fd (diff)
downloadcpython-626668912f3102a96d3f251f5304ad2f8326f3cc.zip
cpython-626668912f3102a96d3f251f5304ad2f8326f3cc.tar.gz
cpython-626668912f3102a96d3f251f5304ad2f8326f3cc.tar.bz2
gh-81263: Add assignment expressions to `help` (#124641)
* Add assignment expression (:=) to `help` * Update index for Assignment Expressions to include pair of `assignment; expression`
Diffstat (limited to 'Lib/pydoc_data/topics.py')
-rw-r--r--Lib/pydoc_data/topics.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/pydoc_data/topics.py b/Lib/pydoc_data/topics.py
index 4643df8..97bb4eb 100644
--- a/Lib/pydoc_data/topics.py
+++ b/Lib/pydoc_data/topics.py
@@ -416,6 +416,34 @@ topics = {'assert': 'The "assert" statement\n'
'some expressions (like un-parenthesized tuple expressions) '
'caused a\n'
'syntax error.\n',
+ 'assignment-expressions': 'Assignment expressions\n'
+ '**********************\n'
+ '\n'
+ 'An assignment expression (sometimes also called a “named expression”'
+ '\nor “walrus”) assigns an expression to an identifier, while also\n'
+ 'returning the value of the expression.\n'
+ '\n'
+ 'One common use case is when handling matched regular expressions:\n'
+ '\n'
+ ' if matching := pattern.search(data):\n'
+ ' do_something(matching)\n'
+ '\n'
+ 'Or, when processing a file stream in chunks:\n'
+ '\n'
+ ' while chunk := file.read(9000):\n'
+ ' process(chunk)\n'
+ '\n'
+ 'Assignment expressions must be surrounded by parentheses when used as\n'
+ 'expression statements and when used as sub-expressions in slicing,\n'
+ 'conditional, lambda, keyword-argument, and comprehension-if\n'
+ 'expressions and in assert, with, and assignment statements. In all\n'
+ 'other places where they can be used, parentheses are not required,\n'
+ 'including in if and while statements.\n'
+ '\n'
+ 'Added in version 3.8.\n'
+ 'See also:\n'
+ '\n'
+ ' **PEP 572** - Assignment Expressions\n',
'async': 'Coroutines\n'
'**********\n'
'\n'