What does isinstance(True, int) return in Python?
-
A
None
-
B
TypeError
-
C
False
-
D
True
Correct answer
24 views
Explanation
bool is a subclass of int in Python (True == 1 and False == 0), so the check passes. This surprises many developers when validating inputs.
Reference
Asked in: NTS, Python Developer Interviews
Doubts & discussion
Not sure why the answer is D? Ask here and get an explanation.
Ask a doubt about this MCQ