LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Predict the Output · Question 2

isinstance and issubclass Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

What is the output of the following Python program?

main.py
class Animal: pass
class Dog(Animal): pass

d = Dog()
print(isinstance(d, Animal), type(d) == Animal, issubclass(bool, int), issubclass(Animal, object))
  • A True True True True
  • B False False True True
  • C True False False True
  • D True False True True Correct
Correct Answer: Option D

isinstance respects inheritance; type() gives the exact class. bool subclasses int and every class subclasses object.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links