all Python 3operatorfunction
operator.floordiv
arithmetic
Return a // b — floor division (the functional form of `//`).
Syntax
operator.floordiv(a, b)
Rounding goes down, towards minus infinity, not towards zero: floordiv(-7, 2) is -4, not -3 as in C or Java. With floats the result is a float too: floordiv(7.5, 2) gives 3.0. When you need both quotient and remainder, divmod returns them in one call and guarantees the pair is consistent.
Examples
import operator
print(operator.floordiv(7, 2)) # → 3
print(operator.floordiv(7, 2) == 7 // 2) # → True
print(operator.floordiv(-7, 2)) # → -4
print(list(map(operator.floordiv, [10, 20, 30], [3, 3, 4]))) # → [3, 6, 7]
print(operator.floordiv(1, 0)) # → ZeroDivisionError
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy