Python Glossary Русский

all Python 3Arithmetic & operatorsconstruct

_

assignment

The underscore _ is the conventional name for an unwanted value, the catch-all pattern in case _, the last result in the REPL, and the digit separator in 1_000_000.

Syntax

for _ in range(n): ...
first, _, last = triple
case _:
1_000_000

As a variable, _ is an ordinary name: Python does not throw anything away, the value is kept until the next assignment. That breaks code using gettext, where _ is the translation function: for _ in range(3) overwrites it, and _('text') fails with TypeError. In match, _ is a soft keyword: case _ always matches and binds nothing, so the old value of the variable _ stays. The interactive interpreter stores the last expression result in _ — but only until you assign _ yourself, then it stops updating. In numbers, _ separates digits and does not change the value.

Examples

first, _, last = (1, 2, 3)
print(first, last)  # → 1 3
print(_)  # → 2 — значение не выброшено
print(1_000_000 + 1)  # → 1000001
# Python 3.10+
_ = 'старое'
match 42:
    case _:
        print('совпало')  # → совпало
print(_)  # → старое — case _ ничего не связывает
import gettext
_ = gettext.gettext
for _ in range(2):
    pass
_('Привет')  # → TypeError: 'int' object is not callable

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy