ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(sum([True, True, False]), True * 3, 'ab' * True, [0] * True)
  1. A. 2 3 abab [0]
  2. B. 2 3 ab [0]
  3. C. 2 3 ab [0, 0]
  4. D. 1 3 ab [0]

Correct answer: B. 2 3 ab [0]

bool is a subclass of int, so True counts as 1 in sums, products and repetition. 'ab' * True repeats the string once and [0] * True gives one element.

More Python Programming questions

Exams that ask this topic