Classes & Objects · Question 15 · Medium

B is a child of A. What do isinstance, a direct type comparison and issubclass report for an object of B?

class A:
    pass

class B(A):
    pass

b = B()
print(isinstance(b, A), type(b) == A, issubclass(A, B))
  1. True True False
  2. True False False
  3. False False True
  4. True False True
Answer and explanation

Answer: B. True False False

Explanation: isinstance accepts parent classes, so a B object counts as an A. type(b) is exactly B, not A. issubclass(A, B) asks whether A derives from B, which is the wrong way round.

Previous: What is the key difference between a method marked @classmethod and one marked… · Next: D inherits from both B and C, and B and C both inherit from A. Which who()…

Practise classes & objects

Try a fresh set of classes & objects questions with an explanation after every answer, free and without signing up: Classes & Objects practice. Or sit a full placement mock test.

More classes & objects questions

More python practice

Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators · Python Strings · Lists & Tuples · Dictionaries & Sets · Conditions & Loops · Functions & Scope

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