Computer >> Computer tutorials >  >> Programming >> Python

What is right shift (>>) operator in Python?


In Python >> is called right shift operator. It is a bitwise operator. It requires a bitwise representation of object as first operand. Bits are shifted to right by number of bits stipulated by second operand. Leading bits as towards left as a result of shifting are set to 0.

>>> bin(a)     #binary equivalent 0110 0100
'0b1100100'
>>> b=a>>2     #binary equivalent 0001 1101
>>> b
25
>>> bin(b)
'0b11001'