QuestionQ53

VerifiedComputer Programming and Python Fundamentals

What is the output of the following code snippet?

Question Image

Explanation

The ^ operator performs bitwise XOR. Starting with a = 1 and b = 0, a = a ^ b sets a to 1 ^ 0 = 1. The next assignment, b = a ^ b, sets b to 1 ^ 0 = 1. The fifth line assigns to b again, setting b to 1 ^ 1 = 0, while a remains 1. Therefore print(a, b) outputs 1 0, which is option D.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!