Python Glossary Русский

all Python 3Arithmetic & operatorsterm

- subtraction

arithmetic

The binary subtraction operator. The unary minus changes the sign of a number.

Syntax

a - b | -a

Unary minus binds more loosely than exponentiation: -2 ** 2 parses as -(2 ** 2) and gives -4, not 4, so wrap the base in parentheses if you meant the square of a negative number. With floats a difference is almost never exact — 0.3 - 0.1 is not exactly 0.2 — so never compare the result of a subtraction with ==; use math.isclose() instead.

Examples

print(10 - 3)  # → 7
print(3.5 - 1.1)  # → 2.4 (float)
x = 5; print(-x)  # → -5 (унарный минус)
print(0 - 100)  # → -100
from datetime import date
delta = date(2025, 12, 31) - date(2025, 1, 1)
print(delta.days)  # → 364 (разница дат)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy