ProgrammingHardTCS NQT · Wipro pattern

What is printed?

What is printed?
print(True + True, 3 * True, 'ab' * True)
  1. A. 2 3 abab
  2. B. 2 3 ab
  3. C. 2 True ab
  4. D. 1 3 ab

Correct answer: B. 2 3 ab

bool is an int subclass, so True acts as 1 in arithmetic and in repetition. 'ab' * True is 'ab'.

More Python Programming questions

Exams that ask this topic