ProgrammingHardProduct-company MCQ pattern
What is printed?
What is printed?
print((1 << 3) - 1 << 2, 1 << 3 - 1 << 2, 1 + 2 << 1, 3 & 2 ** 2)
- A. 28 4 6 0
- B. 28 16 9 0
- C. 28 16 6 4
- D. 28 16 6 0
Correct answer: D. 28 16 6 0
In 1 << 3 - 1 << 2, subtraction binds tighter than shifts, so it is 1 << 2 << 2 = 16. Addition also binds tighter than <<, so 1 + 2 << 1 is 6, and & binds looser than **, giving 3 & 4 = 0.
More Python Programming questions
- What is printed? python print(0 0, 0.0 0, (-8) 0, (-2) 3, -2 3)
- What is printed on the first line? python print(sorted(['10', '9', '2'], key=int)) print(sorted(['10', '9', '2'])) print(sorted(['a', 'B'…
- What is printed? python print('a' 'b' 2, ('a' 'b') 2, 'ab' 0 == '', 'x' 3 + 'y' 2)
- What is printed? python print('%.2f' % 2.675, '%.2f' % 2.665, round(2.665, 2), format(2.5, '.0f'), format(0.125, '.2f'))
- What is printed? python print(0.1 + 0.2 + 0.3 == 0.6, 0.3 + 0.2 + 0.1 == 0.6, 0.1 + (0.2 + 0.3) == 0.6)
- What is printed? python from decimal import Decimal print(Decimal('0.1') + Decimal('0.2') == Decimal('0.3'), Decimal(0.1) ==…