views:

110

answers:

3

What does the >> operator do?

For example 10 >> 1 = 5

Thanks

+6  A: 

It's the right bit shift operator, 'moves' all bits once to the right.

10 in binary is

1010

shifted to the right it turns to

0101

which is 5

Eton B.
note: in this example it moves them once because of the '1' on the right side of the bit shift operator.
Eton B.
+1  A: 

See section 5.7 Shifting Operations in the Python Reference Manual.

They shift the first argument to the left or right by the number of bits given by the second argument.

Zack Mulgrew
+1  A: 

Its the right shift operator.

10 in binary is 1010 now >> 1 says to right shift by 1, effectively loosing the least significant bit to give 101, which is 5 represented in binary.

In effect it divides the number by 2.

codaddict