Python Glossary Русский

all Python 3Arithmetic & operatorsterm

// floor division

arithmetic

The floor division operator. It returns the largest integer not greater than the quotient. With float operands it returns a float.

Syntax

a // b

Rounding goes toward minus infinity, not toward zero as in C or Java: -7 // 2 is -4, while int(-7 / 2) is -3. // and % stay consistent — a == (a // b) * b + a % b — which is why the remainder takes the sign of the divisor. A zero divisor raises ZeroDivisionError, and on very large integers // stays exact whereas math.floor(a / b) pushes the numbers through float and loses precision.

Examples

print(7 // 2)  # → 3
print(-7 // 2)  # → -4 (округление к меньшему, не к нулю!)
print(7.5 // 2)  # → 3.0 (float аргумент → float результат)
print(100 // 10)  # → 10
seconds = 3661
print(seconds // 3600)  # → 1 (полные часы)
print(seconds % 3600 // 60)  # → 1 (минуты)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy