Skip to content

Commit 3dee0cb

Browse files
encukoubrandtbucherFidget-Spinnerambv
authored
[docs] lexical_analysis: Expand the text on _ (GH-28903)
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 <[email protected]> Co-authored-by: Ken Jin <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
1 parent 6fafc25 commit 3dee0cb

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

Doc/reference/lexical_analysis.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,29 @@ classes are identified by the patterns of leading and trailing underscore
385385
characters:
386386

387387
``_*``
388-
Not imported by ``from module import *``. The special identifier ``_`` is used
389-
in the interactive interpreter to store the result of the last evaluation; it is
390-
stored in the :mod:`builtins` module. When not in interactive mode, ``_``
391-
has no special meaning and is not defined. See section :ref:`import`.
388+
Not imported by ``from module import *``.
389+
390+
``_``
391+
In a ``case`` pattern within a :keyword:`match` statement, ``_`` is a
392+
:ref:`soft keyword <soft-keywords>` that denotes a
393+
:ref:`wildcard <wildcard-patterns>`.
394+
395+
Separately, the interactive interpreter makes the result of the last evaluation
396+
available in the variable ``_``.
397+
(It is stored in the :mod:`builtins` module, alongside built-in
398+
functions like ``print``.)
399+
400+
Elsewhere, ``_`` is a regular identifier. It is often used to name
401+
"special" items, but it is not special to Python itself.
392402

393403
.. note::
394404

395405
The name ``_`` is often used in conjunction with internationalization;
396406
refer to the documentation for the :mod:`gettext` module for more
397407
information on this convention.
398408

409+
It is also commonly used for unused variables.
410+
399411
``__*__``
400412
System-defined names, informally known as "dunder" names. These names are
401413
defined by the interpreter and its implementation (including the standard library).

0 commit comments

Comments
 (0)