Guide
Python
Intermediate
5.17 Interview Questions
Frequently asked and scenario-based Python data type interview questions covering list vs tuple, bool as an int subclass, mutable defaults, and JSON type mapping.
Frequently Asked Questions
- What is the difference between a list and a tuple?
- Why is
boolconsidered a subclass ofint? - What’s the difference between
==andis? - Why can’t a list be used as a dictionary key, but a tuple can?
- What is the mutable default argument bug, and how do you fix it?
- What is the difference between
type()andisinstance()?
Scenario-Based Questions
- You need to store a million IP addresses and check membership repeatedly and fast — which type do you choose, and why?
- A function silently accumulates data across unrelated calls — what bug pattern should you suspect first?
- Given a parsed JSON API response, what Python types will the JSON object, array, string, number, true/false, and null become?
- Why might
0.1 + 0.2 == 0.3evaluate toFalse, and how would you compare floats safely instead?
Quick Interview Answer
“The data-type questions that come up most are: list vs tuple (mutability, hashability), why
boolis a subclass ofint,==vsis(value vs identity), why only hashable/immutable types work as dict keys, and the mutable default argument bug. Scenario questions usually test whether you’d reach for asetfor fast membership checks, and whether you know JSON’strue/false/nullmap tobool/Nonein Python.”
Common Mistakes
- Answering “list and tuple are basically the same” without mentioning the mutability difference and its downstream consequences (hashability, dict-key eligibility).
- Not being able to explain why the mutable default argument bug happens (default values are evaluated once, at function definition time), only that it’s “a gotcha.”
Add More Questions to This Guide
Know a question that should be here? Share it and help the community!
Open Google Form