ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
a, b = 5, 9 a ^= b b ^= a a ^= b print(a, b, a ^ b)
- A. 5 9 12
- B. 9 5 0
- C. 9 5 12
- D. 9 5 14
Correct answer: C. 9 5 12
Three XORs swap two values without a temporary variable. After the swap the XOR of the two numbers is unchanged, and 5 ^ 9 is 12.
More Python Programming questions
- What is printed? python print(0xFF >> 4 << 4 == 0xF0, 1 << 63 > 0, (1 << 63) - 1 == 263 - 1, -(1 << 63) >> 63)
- What is printed on the third line? python names = ['bob', 'Alice', 'carl', 'Bob', 'alice'] print(sorted(names)) print(sorted(names…
- What is printed? python x = 253 print(float(x + 1) == x, x + 1.0 == x, (x + 2.0) - x, int(float(x + 3)) - x)
- What is printed? python print([10, 20, 30][True], (5).bitlength(), (True).bitlength(), (-1).bitlength())
- What is printed? python print(round(7.5), round(6.5), round(-7.5), round(7.5000001))
- What is printed? python print(-7.5 % 2, 7.5 % -2, -0.0 % 3)