ProgrammingHardProduct-company MCQ pattern

What is printed?

What is printed?
print(str(True) + str(1 == 1.0), True + True, '3' * True, [0] * True)
  1. A. TrueTrue 2 3 [0]
  2. B. TrueTrue 2 3 [0, 0]
  3. C. TrueTrue 2 1 [0]
  4. D. TrueTrue 3 3 [0]

Correct answer: A. TrueTrue 2 3 [0]

bool is a subclass of int, so True + True is 2. Repetition by True uses it as 1, so '3' * True is '3' and [0] * True is [0].

More Python Programming questions

Exams that ask this topic