all Python 3operatorfunction
operator.irshift
in-place
In-place right shift: a >>= b.
Syntax
operator.irshift(a, b)
Assign the result: x = irshift(x, 1) — built-in types with >>= are immutable. For negative numbers the shift rounds towards minus infinity: -5 >> 1 gives -3. This matters in a "shift until zero" loop: a negative number never reaches zero by right shifts and gets stuck at -1.
Examples
import operator
print(operator.irshift(16, 2)) # → 4
print(operator.irshift(5, 10)) # → 0
color = 0xFF8800 # достать старший байт цвета
print(operator.irshift(color, 16)) # → 255
print(operator.irshift(-17, 2)) # → -5
print(operator.irshift(1, -1)) # → ValueError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy