What does the caret operator (^) in Python do?

前端 未结 5 1751
忘了有多久
忘了有多久 2020-11-28 04:19

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
>         


        
5条回答
  •  渐次进展
    2020-11-28 05:07

    It's a bit-by-bit exclusive-or. Binary bitwise operators are documented in chapter 5 of the Python Language Reference.

提交回复
热议问题