ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print([10, 20][True], [10, 20][False])
  1. A. 20 10
  2. B. 10 20
  3. C. 20 20
  4. D. TypeError

Correct answer: A. 20 10

bool is a subclass of int, and True equals 1 when used as an index. So [10, 20][True] reads index 1, which holds 20.

More Python Programming questions

Exams that ask this topic