ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print(7 & 3 << 1, 7 & (3 << 1), 6 | 1 << 2, (6 | 1) << 2)
- A. 6 6 6 28
- B. 6 6 6 24
- C. 4 6 6 28
- D. 6 6 7 28
Correct answer: A. 6 6 6 28
Shifts bind tighter than & and |, so 3 << 1 is 6 and 7 & 6 is 6. 1 << 2 is 4, and 6 | 4 is 6, while (6 | 1) << 2 is 7 << 2 = 28.
More Python Programming questions
- What is printed? python print(~0, ~-1, -~0, ~~5, -~-5)
- What is printed? python print(max(map(int, '3 17 9'.split())), min(map(int, '3 17 9'.split())), sorted('3 17 9'.split())[-1])
- What is printed? python print(sorted(['1.10', '1.9', '1.10.1'], key=lambda v: tuple(map(int, v.split('.')))))
- What is printed? python print(sorted(['1.10', '1.9', '1.10.1']))
- What is printed? python values = [2.0, 2, '2'] print(len(set(values[:2])), len(set(values)), values[0] == values[1] == 2)
- What is printed? python t = 3 print(t // 2 if t % 2 else t / 2, 1 if t else 0, t and 0, t or 0, not t)