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)
  1. A. 28 4 6 0
  2. B. 28 16 9 0
  3. C. 28 16 6 4
  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

Exams that ask this topic