Python is now the preferred language for DSA rounds at most Indian product companies — Flipkart, Swiggy, CRED, Amazon, and Google all accept it. It's also the primary language for data science and ML interviews. But Python interview questions are deceptively tricky — the language's features (mutable defaults, GIL, generators) generate questions Java doesn't. Here are the 50 that matter most.
Core Python — Fundamentals Still Get Asked
1. What is the difference between a list and a tuple?
List: mutable, uses [], slower iteration. Tuple: immutable, uses (), faster iteration and hashable (can be dict key). Use tuple for fixed data (coordinates, RGB values), list for data that changes.
2. What is the GIL (Global Interpreter Lock)?
CPython's mutex that prevents multiple threads from executing Python bytecode simultaneously. This means CPU-bound threads don't speed up on multi-core machines. Solutions: multiprocessing (separate processes), asyncio for I/O-bound tasks, Cython or C extensions.
3. What are mutable default arguments and why are they dangerous?
Common Python gotcha: def add(item, lst=[]) reuses the same list across calls. Python evaluates default arguments once at function definition time. Fix: use None as default and create inside function.
4. What is *args and **kwargs?
*args: variable positional arguments — packed as tuple. **kwargs: variable keyword arguments — packed as dict. Used to write flexible functions that accept any number of arguments.
5. What is list comprehension vs generator expression?
List comprehension: [x*2 for x in range(10)] — creates the full list in memory immediately.
Generator: (x*2 for x in range(10)) — lazy evaluation, yields one item at a time. Generators are more memory-efficient for large data.
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.lru_cache (memoisation). The @login_required 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.
Python 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 — bisect_left(), bisect_right()
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
Ready to practice?
Practice Python technical questions in a voice mock interview on HireStepX — explain your code and reasoning out loud, scored by AI in real time.
Start free practice