What does the >> operator do in Python?

Java 8Object Oriented ProgrammingProgramming

It is a bitwise right shift operator. The bit pattern is shifted towards right by number of places stipulated by operand on right. Bits on left are set to 0

For example a=60 (00111100 in binary), a>>2 will result in 15 (00001111 in binary)

>>> a=60
>>> bin(a)result #39;0b111100'
>>> b=a>>2
>>> bin(b)
'0b1111'
raja
Published on 12-Feb-2018 05:23:14
Advertisements