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

PythonServer Side ProgrammingProgramming

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'
raja
Published on 13-Feb-2018 13:49:13
Advertisements