What is the output of the following Python code? print(5 & 3, 5 | 3, 5 ^ 3)
Correct answer C. 1 7 6
Explanation
In binary 5 is 101 and 3 is 011. Bitwise AND keeps bits set in both (001 = 1), OR keeps bits set in either (111 = 7), and XOR keeps bits set in exactly one (110 = 6). A common slip is to treat ^ as exponentiation, which is written ** in Python.
Answer checked How we write and check questions
Discussion