Python interview questions come up in data engineering, backend development, data science, and automation roles. This page covers every Python interview resource on TheCodeForge — from syntax basics to Django and advanced patterns.
Python interviews split sharply by role, and preparing for the wrong split is the most common wasted effort. Backend interviews probe the data model — mutability, scoping, decorators, generators, the GIL. Data and ML interviews probe pandas, NumPy semantics and statistics, and treat the language as a given. Automation and SRE interviews probe the standard library and process handling.
What is common to all three is that Python's convenience hides mechanism, and interviewers probe exactly there. Mutable default arguments, late-binding closures and identity versus equality are asked so often because they are where the surface simplicity stops matching what the interpreter does.
| Question | The trap | The real answer |
|---|---|---|
| What does a mutable default argument do? | Assuming def f(x=[]) gets a fresh list per call | The default is evaluated once at definition time and shared across every call. Use None as the sentinel |
| is versus == | Small-integer and string interning makes is appear to work | is compares identity, == compares value. Use is only for None, True, False |
| What does the GIL prevent? | Concluding Python cannot do concurrency | One thread executes bytecode at a time, so threads do not help CPU-bound work — but they are fine for I/O-bound work, and multiprocessing sidesteps it entirely |
| Generator versus list comprehension | Treating them as interchangeable syntax | A generator is lazy and holds one item at a time; a list materialises everything. The difference is memory, and it is the difference between working and failing on a large file |
| What does a decorator actually do? | Describing the syntax rather than the semantics | It is a function taking a function and returning a replacement, applied at definition time. @d is f = d(f) |
| Shallow versus deep copy | Assuming a copy is independent | A shallow copy duplicates the container and shares the nested objects, so mutating a nested list is visible through both |
The single most useful thing you can demonstrate is knowing which of Python's three concurrency models fits a given workload, and why. Say the classification before the solution and most follow-up questions answer themselves.
I/O-bound, many operations: asyncio — thousands of outstanding operations on one thread, no GIL contention because nothing is computing. I/O-bound, blocking libraries: threads, because the GIL is released during I/O. CPU-bound: multiprocessing or a native extension that releases the GIL — NumPy does this, which is why array operations scale where pure-Python loops do not.
For data and ML positions, the language questions thin out and are replaced by questions about pandas behaviour — which is reasonable, because that is where the bugs are. The SettingWithCopyWarning, the difference between loc and iloc, why chained indexing is unreliable, how merges duplicate rows, and how NaN propagates through aggregations all come up repeatedly.
The underlying theme matches the database section of any backend interview: know whether you are looking at a view or a copy, and know what a join does to your row count. Those two questions catch most real pandas bugs.
collections (defaultdict, Counter, deque), itertools, functools, dataclasses, pathlib, json, re, typing. Knowing Counter exists turns several interview problems into three lines, which is itself a signal.Optional, generics and protocols shows you have worked on code other people maintain. They are not checked at runtime, which is worth saying explicitly.X | Y union syntax, better error messages. Mentioning that you know when a feature landed is a small but real signal of currency.heapq and slicing make many solutions short. The trade is that interviewers expect idiomatic use, so a C-style index loop where a comprehension or enumerate belongs reads poorly even when the answer is correct.74 interview topics across coding patterns, HR questions, aptitude and more.
View All Interview Topics →