ProgrammingVery hardProduct-company MCQ pattern
What is printed?
What is printed?
print(5 & 6 | 1, 5 & (6 | 1), 5 ^ 6 & 1, 1 | 2 ^ 3 & 4)
- A. 5 5 5 7
- B. 4 5 5 3
- C. 5 5 4 3
- D. 5 5 5 3
Correct answer: D. 5 5 5 3
In Python & binds tighter than ^, which binds tighter than |. So 5 & 6 | 1 is (4) | 1 = 5, 5 ^ (6 & 1) = 5, and 1 | (2 ^ (3 & 4)) = 3.
More Python Programming questions
- What is printed? python print(-1 >> 1, -1 << 2, -5 >> 10, 5 >> -0 if False else 0)
- What is printed? python print(bin(-1 & 0b111), (-1) & 0xF == 15, -16 >> 2, -15 >> 2)
- What is printed? python print(''.join(sorted(set('mississippi'))), ''.join(sorted('mississippi', key=lambda c: (-'mississippi'.count(c)…
- What is printed? python print(str(1.1 1.1), str(1.21), 1.1 1.1 == 1.21, abs(1.1 1.1 - 1.21) < 1e-12)
- What is printed? python print(10 2 == 100.0, 2 0.5 2 == 2 0.25, pow(4, 0.5))
- What does ','.join([1, 2]) do in Python 3?