ProgrammingModerateTCS NQT · Wipro pattern

What is printed?

What is printed?
print(True + True * 3, type(True + 1).__name__)
  1. A. 4 bool
  2. B. 6 int
  3. C. 4 int
  4. D. TrueTrueTrueTrue bool

Correct answer: C. 4 int

bool is a subclass of int, with True = 1. * binds tighter than +, so True + True * 3 = 1 + 3 = 4. Arithmetic on bools returns an int.

More Python Programming questions

Exams that ask this topic