all Python 3operatorfunction
operator.inv
bitwise
An alias of operator.invert: bitwise inversion ~a.
Syntax
operator.inv(a)
The documentation describes inv and invert together: two names for the one ~ operation. They are separate objects with identical behaviour, not one function under two names, so inv is invert is False. New code should prefer invert, whose name matches the special method __invert__.
Examples
import operator
print(operator.inv(5)) # → -6
print(operator.inv(5) == ~5) # → True
print(operator.inv(5) == operator.invert(5)) # → True
print(list(map(operator.inv, [0, 1, -1]))) # → [-1, -2, 0]
print(operator.inv(2.0)) # → TypeError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy