Operators

>>= — Right-shift assignment

Shift a built-in integer right by a nonnegative integer count. For integers this behaves like floor division by a power of two, including negative values. A negative shift count is invalid. The __irshift__() hook may modify its receiver or supply a replacement. If absent or declining with NotImplemented, normal binary dispatch applies. The result is stored back into the target; this is a statement, not an expression. A failed store does not guarantee rollback.

Formal Syntax & Structure

python syntaxpython
target >>= expression

Parameters & Attributes

NameTypeDescription
targetobjectExisting assignable name, attribute, item or slice; its current value participates in the operation.
rightnonnegative integer shift countValue used as the right operand of the operation.

Working Example

Example Snippetpython
mask = 0b110100mask >>= 2negative = -7negative >>= 1print(mask)print(negative)
Python Reference