-1

Possible Duplicate:
Python - '>>' operator

What does the >> operator means in Python? ie:

x = x + str(n%2)
n >> 1

Thank you

6
  • 4
    I suggest an internet search for python operators and clicking on the first hit. Commented Feb 8, 2012 at 21:43
  • Bitwise shift right Commented Feb 8, 2012 at 21:44
  • This is the complete list: docs.python.org/library/… Commented Feb 8, 2012 at 21:45
  • Here's a convenient link to further reading about what bit shifting is/does: en.wikipedia.org/wiki/Bit_shift#Bit_shifts Commented Feb 8, 2012 at 21:46
  • @aganders3 - note that the OP didn't know what the operator did, so the bit shift wiki would not have been helpful -- other than as a side door answer to the question :) Commented Feb 8, 2012 at 22:17

4 Answers 4

4

n >> 1 shifts n right 1 bit. This is the same as dividing by 2.

More generally, n >> m shifts n right m bits, giving a division by 2^m.

See also:

Sign up to request clarification or add additional context in comments.

Comments

3

Just for completeness, note that there's a completely different usage which is changing the stream that print uses by default:

print >> sys.stderr, message

For more information, please have a look at this related question.

Comments

0

That's the right shift operator.

Comments

0

It's the bitshift operator:

x >> n  

x shifted right by n bits.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.