Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

Operator >>

Shifts integer bits right by the count on the right.

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

Syntax

left >> right

Shifts integer bits right by the count on the right.

Use a right shift to discard low bits before decoding a packed integer field. Shifting a positive integer far enough eventually gives zero.

Negative integers use sign extension, so sufficiently large right shifts give minus one. A negative shift count raises a value error.

A signed right shift uses floor division by a power of two, including for negative inputs.

Syntax

left >> right

__rshift__, __rrshift__ · ValueError

Worked example

-7 >> 1 → -4
7 >> 10 → 0
7 >> -1 → ValueError

Examples

print(19 >> 2)
print(-19 >> 2)

Result

4
-5

A signed right shift uses floor division by a power of two, including for negative inputs.

Sources