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'
Updated on: 2020-02-26T10:37:00+05:30

11K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements