ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
a = 1 if 3 > 2 else 0
print(a << 3 | 1, a << (3 | 1), 2 + 3 * 4 ** 2 // 8 % 5)
  1. A. 9 8 18
  2. B. 9 24 3
  3. C. 9 8 3
  4. D. 9 8 1

Correct answer: C. 9 8 3

<< binds tighter than |, so a << 3 | 1 is 9. ** binds tightest, then * // % from left to right, so 3 * 16 // 8 % 5 is 1 and the total is 3. Mixing up the order of * and // gives 18.

More Python Programming questions

Exams that ask this topic