LearnFrenzy
Sign in Take a free test

Variables and Data Types · Predict the Output · Question 14

isinstance() and type() with True Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 14 Back to Exercise

What is the output of the following Python program?

main.py
print(isinstance(True, int), type(True) == int, True == 1, True + 0.5)
  • A True True True 1.5
  • B False False True TypeError
  • C True False True 1.5 Correct
  • D True False False True0.5
Correct Answer: Option C

bool is a subclass of int, so isinstance() is True, but its exact type is bool, so type(True) == int is False. In arithmetic True counts as 1, giving 1.5.

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