What does ^ operator do in Python?

Question:

I’ve tried the following:

print(1^3) #output 2
print(1^5) #output 4
print(1^6) #output 7

These outputs don’t make any sense for me.

Asked By: Victor Rayan

||

Answers:

It’s the bitwise XOR operator.

Answered By: RedBox
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.