ProgrammingHardGATE CS · Product-company placement
What is printed?
What is printed?
print(5 & 3, 5 | 3, 5 ^ 3, ~5, 5 << 2, -5 >> 1)
- A. 1 7 6 -6 20 -2
- B. 1 7 6 -6 20 -3
- C. 1 7 6 -5 20 -3
- D. 1 7 6 -6 10 -3
Correct answer: B. 1 7 6 -6 20 -3
~x equals -x - 1, so ~5 is -6, and >> is an arithmetic shift that floors, so -5 >> 1 is -3, not the truncated -2.
More Python Programming questions
- What is printed? python print(-1 & 0xFF, -8 >> 1, -1 >> 100, -9 & 7)
- What is printed? python print(1 << 64 == 264, (1 << 64) - 1 & 0xFFFF)
- What is printed? python print(0.1 + 0.2 == 0.3, round(0.1 + 0.2, 10) == 0.3, 0.1 + 0.2)
- What is printed? python print(round(2.5), round(3.5), round(-0.5), round(2.675, 2), round(1.005, 2))
- What is printed? python a = float('nan') b = float('nan') print(a == a, a is a, a == b, [a] == [a], [b] == [a])
- What is printed? python print(253 + 1 == 253 + 1.0, 253 + 1 == 253, float(253 + 1) == 253)