Built-ins & Standard Library · Question 5 · Easy

isinstance is given a tuple of types in one call and a single type in the other. What does this code print?

print(isinstance(5, (int, str)), isinstance("5", int))
  1. True True
  2. False False
  3. TypeError
  4. True False
Answer and explanation

Answer: D. True False

Explanation: With a tuple, isinstance checks whether the object is an instance of any of the listed types, and 5 is an int. The string "5" is not an int, even though it looks like a number.

Previous: A program starts with the line import math as m. Which call correctly computes… · Next: math.floor is applied to a negative number and math.ceil to a positive one…

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