What does the >> operator do in Python?


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'

Updated on: 26-Feb-2020

302 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements