all Python 3operatorfunction
operator.ifloordiv
in-place
In-place floor division: a //= b.
Syntax
operator.ifloordiv(a, b)
Built-in types change nothing in place — int and float are immutable, so assign the result: x = ifloordiv(x, 2). Rounding, as with //, goes towards minus infinity: -7 and 2 give -4. A user class can mutate in place by defining __ifloordiv__.
Examples
import operator
print(operator.ifloordiv(7, 2)) # → 3
print(operator.ifloordiv(7, 2) == 7 // 2) # → True
print(operator.ifloordiv(-7, 2)) # → -4
print(list(map(operator.ifloordiv, [10, 20, 30], [3, 6, 7]))) # → [3, 3, 4]
print(operator.ifloordiv(7, 0)) # → ZeroDivisionError
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy