# python
// [38] real interview questions. Answers and sources live in the practice app.
practice this topic- What is the Global Interpreter Lock (GIL), and in which workloads does it actually matter?(mid)
- A teammate parallelized a CPU-heavy data transformation with threading and saw no speedup. Why, and what would you change?(mid)
- What is wrong with def add_item(item, items=[]) and how do you fix it?(junior)
- When would you use a generator instead of building a list, and what trade-offs come with that choice?(mid)
- What are decorators, and what real problems have you used them for?(mid)
- How do context managers work under the hood, and how would you write your own?(mid)
- You must handle 10k concurrent outbound HTTP calls. Compare asyncio, threads, and processes for this job.(senior)
- What is the difference between == and is in Python, and when does using the wrong one bite?(junior)
- How does CPython manage memory — what do reference counting and the cyclic garbage collector each handle?(senior)
- What is the difference between a shallow copy and a deep copy, and when does a shallow copy give surprising results?(junior)
- Why do lambdas defined in a loop all return the last value of the loop variable, and how do you fix it?(mid)
- Explain *args and **kwargs. Where do they genuinely help, and where do they hurt?(junior)
- Why must dictionary keys be immutable (hashable)?(mid)
- How are Python dictionaries implemented, and what performance characteristics follow from that?(senior)
- Do type hints change how Python runs? How would you introduce typing into a large untyped codebase?(mid)
- What is duck typing, and how do Protocols reconcile it with static type checking?(mid)
- What do EAFP and LBYL mean, and how expensive are exceptions in Python?(mid)
- Why are Python strings immutable, and what does that imply for building a large string in a loop?(junior)
- Your async web service 'freezes' for seconds at a time under load — even health checks stall. What blocked the event loop, how do you find it, and how do you fix it?(senior)
- You fire-and-forget background work with asyncio.create_task and sometimes it silently never finishes — or errors vanish. What is going on?(mid)
- A long-running Python worker's memory grows until the container is OOM-killed. Walk through how you would find the leak.(senior)
- Your team is standardizing Python tooling for several services. How do you decide between uv, Poetry, and pip-tools?(mid)
- Your typed codebase has decorators, and every decorated function loses its signature for mypy/pyright. How do you type a decorator properly?(senior)
- Pipeline job: download 50k images over HTTP, CPU-resize each one, upload the results. How do you structure the concurrency?(senior)
- Where does pydantic belong in a service's architecture, and what validation patterns keep it from becoming a performance problem?(mid)
- A colleague converted a function to async, awaits each call in a for loop, and sees zero speedup. Why, and what should the code look like?(mid)
- Your service holds millions of small Python objects and memory is the constraint. What are your options for shrinking per-object overhead?(mid)
- How does cancellation actually work in asyncio, and what mistakes make timeouts unreliable?(senior)
- A CPU-bound endpoint sees no speedup on the free-threaded (no-GIL) 3.13 build, and some pure-Python code even got slower. What is the nuance you would explain?(senior)
- In a data pipeline you keep reaching for dataclasses, NamedTuple, and TypedDict. How do you decide which, and where does pydantic sit relative to them?(mid)
- You want generic, reusable container classes that type-check precisely. How do TypeVars, generic classes, and the 3.12 syntax fit together — and what does variance change?(senior)
- What does functools.lru_cache buy you, and what are the traps that make it a memory or correctness hazard?(mid)
- A CPU profile of a slow Python batch job is confusing — cProfile says one thing, wall-clock says another. How do you profile Python correctly?(senior)
- Under load your service spends most of its time NOT computing. Given a concrete mix of work, argue for asyncio vs threads vs processes.(mid)
- You need duck-typed plugins that a checker can still verify, and you keep hitting the abstract-vs-structural fork. When do you use Protocol vs ABC?(mid)
- A worker using multiprocessing hangs at startup on macOS but ran fine on your Linux box, and passing a database connection to workers fails. What is going on?(senior)
- Your team standardizes on pydantic v2. Which real-world modeling patterns matter, and what changed from v1 that trips people up?(mid)
- You must ship a Python service as a reproducible container. What are the packaging and dependency decisions that decide whether 'works on my machine' becomes 'works in prod'?(senior)