What does the caret operator in Python do?

Posted by Fry on Stack Overflow See other posts from Stack Overflow or by Fry
Published on 2010-03-16T00:21:41Z Indexed on 2010/03/16 0:29 UTC
Read the original article Hit count: 689

Filed under:
|
|

I ran across the caret operator in python today and trying it out, I got the following output:

>>> 8^3
11
>>> 8^4
12
>>> 8^1
9
>>> 8^0
8
>>> 7^1
6
>>> 7^2
5
>>> 7^7
0
>>> 7^8
15
>>> 9^1
8
>>> 16^1
17
>>> 15^1
14
>>>

It seems to be based on 8, so I'm guessing some sort of byte operation? I can't seem to find much about this searching sites other than it behaves oddly for floats, does anybody have a link to what this operator does or can you explain it here?

© Stack Overflow or respective owner

Related posts about python

Related posts about operators