Python Glossary Русский

all Python 3operatorfunction

operator.itruediv

in-place

In-place true division: a /= b.

Syntax

operator.itruediv(a, b)

The result type may change: dividing ints always yields a float, so after x = itruediv(x, 2) a variable that held an int now holds a float — and, for instance, no longer works as a list index. No built-in mutable type supports /=, so the result always has to be assigned.

Examples

import operator
from functools import reduce
print(operator.itruediv(7, 2))   # → 3.5
print(operator.itruediv(9, 3))   # → 3.0
print(reduce(operator.itruediv, [100, 2, 5]))   # → 10.0
print(operator.ifloordiv(7, 2))   # → 3
print(operator.itruediv(1, 0))   # → ZeroDivisionError

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy