Built-ins & Standard Library · Question 17 · Hard

Booleans are used in an isinstance check, in addition and inside sum. What does this code print?

flags = [x > 2 for x in [1, 3, 5]]
print(isinstance(True, int), True + True, sum(flags))
  1. False 2 2
  2. True True 2
  3. True 2 2
  4. True 2 3
Answer and explanation

Answer: C. True 2 2

Explanation: bool is a subclass of int, with True equal to 1 and False equal to 0. So True + True is 2, and summing [False, True, True] counts the two True values.

Previous: itertools.groupby is applied directly to a string in which one letter appears… · Next: A program imports the same module helper from two different files. How many…

Practise built-ins & standard library

Try a fresh set of built-ins & standard library questions with an explanation after every answer, free and without signing up: Built-ins & Standard Library practice. Or sit a full placement mock test.

More built-ins & standard library questions

More python practice

Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge