all Python 3operatorfunction
operator.imod
in-place
In-place modulo: a %= b; for strings, %-formatting.
Syntax
operator.imod(a, b)
For strings % is formatting, not a remainder: imod('%s-%d', ('a', 3)) returns 'a-3'. For numbers the sign of the result follows the divisor, as with mod. Strings and numbers are immutable, so assign the result: s = imod(s, args).
Examples
import operator
print(operator.imod(7, 3)) # → 1
print(operator.imod(7, 3) == 7 % 3) # → True
print(operator.imod(-7, 3)) # → 2
print(list(map(operator.imod, [10, 11, 12], [3, 3, 5]))) # → [1, 2, 2]
print(operator.imod('%s!', 'hi')) # → hi!
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy