Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

Operator >>=

Drops the indicated number of low bits from the stored integer using an arithmetic right shift.

Version: Python 3.14; repository image, production runtime not attested

Syntax

target >>= value

Drops the indicated number of low bits from the stored integer using an arithmetic right shift.

Remove low-order bits from an integer field while storing the shifted result back into the same target. A zero count preserves its value.

Signed right shift rounds a negative quotient down because sign bits are extended. The count must be nonnegative; a negative count raises a value error.

For a negative integer the right shift rounds down when discarded bits are nonzero.

Syntax

target >>= value

__irshift__, __rshift__, __rrshift__ · ValueError

Worked example

n = -7; n >>= 1
n → -4

Examples

value = -19
value >>= 2
print(value)
print(bin(value))

Result

-5
-0b101

For a negative integer the right shift rounds down when discarded bits are nonzero.

Sources