Most candidates preparing for Python interviews study the wrong things. They drill list comprehensions and `lambda` functions, then get blindsided by a question about mutable default arguments: or asked to explain the GIL to an interviewer at a fintech company with no ML ambitions. Python is accepted at Flipkart, Swiggy, CRED, Amazon, and Google for DSA rounds, and it's the default language for every data science and ML interview. But the questions it generates are specific to Python's own quirks: why your function behaves differently on the second call, what `__slots__` actually buys you, when a generator outperforms a list and when it doesn't. This guide covers 50 questions drawn from actual interview rounds: weighted toward the ones that filter people out, not the ones everyone already knows.
Core Python: Fundamentals Still Get Asked
What is the difference between a list and a tuple?
The textbook answer: lists are mutable, tuples are immutable: is table stakes. What interviewers actually want to hear is why that immutability matters in practice. Tuples are hashable, so you can use them as dictionary keys or add them to a set. A list of `(lat, lng)` coordinate pairs is the classic example. Tuples also iterate slightly faster. If you're storing data that won't change, a tuple signals intent to anyone reading your code, not just a performance micro-optimisation.
What is the GIL?
The Global Interpreter Lock is CPython's mutex that ensures only one thread executes Python bytecode at a time: which means CPU-bound multi-threaded Python doesn't actually run in parallel on a multi-core machine. The GIL comes up a lot in backend and ML interviews. The honest answer includes the tradeoffs: for I/O-bound tasks (network calls, disk reads), threads work fine because the GIL is released during I/O. For CPU-bound parallelism, you reach for `multiprocessing` (separate processes, each with its own GIL) or Cython. Mentioning that Python 3.13 introduced experimental free-threaded mode shows you're tracking the language.
Why are mutable default arguments dangerous?
This is one of Python's best interview filters because it looks harmless until it isn't. `def add(item, lst=[])`: that list is evaluated once when the function is defined, not each time it's called. Every invocation shares the same list. The fix is `def add(item, lst=None)` with `lst = lst or []` inside the body. A strong answer explains that this isn't a bug in Python: it's a consequence of functions being first-class objects with their own `_defaults_` attribute.
*What are `args` and `kwargs`?
`args` captures extra positional arguments as a tuple; `kwargs` captures extra keyword arguments as a dictionary. They're tools for writing APIs that accept flexible input without breaking when the caller passes something new. The distinction interviewers probe is the unpacking side: you can pass `mylist` to a function to unpack it into positional arguments, and `**mydict` to unpack keyword arguments. That's where the real gotchas live.
List comprehension vs generator expression
Brackets vs parentheses: `[x2 for x in range(10)]` builds the whole list in memory at once. `(x2 for x in range(10))` is lazy: it yields one item per iteration and holds almost nothing in memory. For small sequences, the difference is irrelevant. For a file with 10 million rows, the generator is the only sensible choice. The follow-up question is almost always: when would you NOT use a generator? Answer: when you need random access (you can't index into a generator) or when you need to iterate the sequence more than once.
OOP in Python
6. What is _init vs new? new: creates the object (called first). init: initialises it (called second). Override new for metaclasses or immutable types (tuple subclasses). For most use cases, only init_ matters.
7. What is the difference between class variable and instance variable? Class variable: shared across all instances (defined outside _init). Instance variable: unique per object (defined with self.x in init_). Mutable class variables shared across instances is another gotcha: changes in one instance affect all.
8. What are Python decorators? Functions that wrap another function: add behaviour without modifying the original. Common uses: @property (getter/setter), @staticmethod, @classmethod, @functools.lrucache (memoisation). The @loginrequired pattern in Django is a real-world example.
9. What is multiple inheritance and MRO? Python supports multiple inheritance. MRO (Method Resolution Order) defines the search order for methods: uses C3 linearisation algorithm. Check with ClassName._mro_ or ClassName.mro().
10. What is _slots? Optimisation: prevents creation of dict per instance, reducing memory usage for objects created in large numbers (100k+ instances). Restricts instance attributes to those declared in slots_.
Python Libraries: Data-Focused Questions
11. What is the difference between shallow copy and deep copy in Python? shallow copy (copy.copy()): copies the object but not nested objects: modifying nested objects affects both copies. deep copy (copy.deepcopy()): copies everything recursively: fully independent.
12. How does Python's dictionary maintain insertion order? From Python 3.7+, dict maintains insertion order as part of the language specification (not just CPython implementation detail). Interviewers sometimes ask about this to test language version awareness.
13. What are Python generators and yield? Generators are lazy iterators: they yield values one at a time, only computing the next value when asked. This allows infinite sequences and memory-efficient pipelines. yield turns any function into a generator. yield from delegates to a sub-generator.
14. What is the difference between is and ==? == tests equality (value comparison). is tests identity (same object in memory). Small integers (-5 to 256) and interned strings are cached by CPython, so a is b may return True unexpectedly for those: always use == for value comparison.
Writing correct Python is one thing. Explaining why your approach is correct: out loud, under pressure, to someone who will ask a follow-up: is a different skill. HireStepX runs voice mock interviews where you narrate your reasoning, and the AI scores both the technical accuracy and how clearly you communicated it.
Practice freePython in DSA Coding Rounds
Python-specific patterns for competitive coding rounds:
Collections module (always import this):
- defaultdict(int): auto-initialises missing keys: replaces freq[key] = freq.get(key, 0) + 1 with freq[key] += 1
- Counter: frequency counter + most_common()
- deque: O(1) append/pop from both ends: use for BFS queues
- heapq: min-heap (for max-heap: negate values)
Bisect module: binary search on sorted arrays: bisectleft(), bisectright()
Common Python DSA patterns:
- sorted(iterable, key=lambda x: ...): custom sort in one line
- list[::-1]: reverse a list
- zip(a, b): pair two lists
- enumerate(iterable): index + value in loop
- any() / all(): boolean aggregation
- set(): O(1) lookup, automatic deduplication
Frequently asked questions
Explore more