diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2021-10-13 16:58:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 16:58:06 (GMT) |
commit | 5abb2dec2cf147ce71cd15bcfda1bd095818f222 (patch) | |
tree | 75562ae6166629c117c1ad6c32b114a35ca33461 | |
parent | 7e74d99c532f3eb55a86d10d30c068b03f2ad025 (diff) | |
download | cpython-5abb2dec2cf147ce71cd15bcfda1bd095818f222.zip cpython-5abb2dec2cf147ce71cd15bcfda1bd095818f222.tar.gz cpython-5abb2dec2cf147ce71cd15bcfda1bd095818f222.tar.bz2 |
[docs] lexical_analysis: Expand the text on ``_`` (GH-28903) (GH-28933)
Also:
* Expand the discussion into its own entry. (Even before this,
text on ``_`` was longet than the text on ``_*``.)
* Briefly note the other common convention for `_`: naming unused
variables.
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>
Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
Co-authored-by: Ćukasz Langa <lukasz@langa.pl>
(cherry picked from commit 3dee0cb6217db326e844955a7f8b424c67990557)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
-rw-r--r-- | Doc/reference/lexical_analysis.rst | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Doc/reference/lexical_analysis.rst b/Doc/reference/lexical_analysis.rst index 4ad8f8b..daa746e 100644 --- a/Doc/reference/lexical_analysis.rst +++ b/Doc/reference/lexical_analysis.rst @@ -385,10 +385,20 @@ classes are identified by the patterns of leading and trailing underscore characters: ``_*`` - Not imported by ``from module import *``. The special identifier ``_`` is used - in the interactive interpreter to store the result of the last evaluation; it is - stored in the :mod:`builtins` module. When not in interactive mode, ``_`` - has no special meaning and is not defined. See section :ref:`import`. + Not imported by ``from module import *``. + +``_`` + In a ``case`` pattern within a :keyword:`match` statement, ``_`` is a + :ref:`soft keyword <soft-keywords>` that denotes a + :ref:`wildcard <wildcard-patterns>`. + + Separately, the interactive interpreter makes the result of the last evaluation + available in the variable ``_``. + (It is stored in the :mod:`builtins` module, alongside built-in + functions like ``print``.) + + Elsewhere, ``_`` is a regular identifier. It is often used to name + "special" items, but it is not special to Python itself. .. note:: @@ -396,6 +406,8 @@ characters: refer to the documentation for the :mod:`gettext` module for more information on this convention. + It is also commonly used for unused variables. + ``__*__`` System-defined names, informally known as "dunder" names. These names are defined by the interpreter and its implementation (including the standard library). |