all Python 3operatorfunction
operator.ior
in-place
In-place bitwise OR: a |= b.
Syntax
operator.ior(a, b)
For a dict since Python 3.9 it equals dict.update: the dict changes in place and the right argument wins on a shared key. For a set it is an in-place union. For ints assign the result — the usual way to accumulate flags: flags = ior(flags, FLAG_X).
Examples
# Python 3.9+
import operator
print(operator.ior(5, 2)) # → 7
read, write = 4, 2 # типовой сценарий: объединение битовых флагов
print(operator.ior(read, write)) # → 6
flags = {'r', 'w'}
print(operator.ior(flags, {'x'}) is flags) # → True
print(sorted(flags)) # → ['r', 'w', 'x']
conf = {'debug': False}
print(operator.ior(conf, {'level': 3})) # → {'debug': False, 'level': 3}
See also
Open in the full glossarydocs.python.orgReport an inaccuracy