ProgrammingModerateGATE CS & IT · Infosys

What is printed?

What is printed?
a, b = 5, 9
a ^= b
b ^= a
a ^= b
print(a, b)
  1. A. 9 5
  2. B. 5 9
  3. C. 0 14
  4. D. 9 9

Correct answer: A. 9 5

Three XOR steps swap two values without a temporary variable. After them a holds 9 and b holds 5.

More Python Programming questions

Exams that ask this topic