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'

Updated on: 26-Feb-2020

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements