# python

// [38] real interview questions. Answers and sources live in the practice app.

practice this topic
  1. What is the Global Interpreter Lock (GIL), and in which workloads does it actually matter?(mid)
  2. A teammate parallelized a CPU-heavy data transformation with threading and saw no speedup. Why, and what would you change?(mid)
  3. What is wrong with def add_item(item, items=[]) and how do you fix it?(junior)
  4. When would you use a generator instead of building a list, and what trade-offs come with that choice?(mid)
  5. What are decorators, and what real problems have you used them for?(mid)
  6. How do context managers work under the hood, and how would you write your own?(mid)
  7. You must handle 10k concurrent outbound HTTP calls. Compare asyncio, threads, and processes for this job.(senior)
  8. What is the difference between == and is in Python, and when does using the wrong one bite?(junior)
  9. How does CPython manage memory — what do reference counting and the cyclic garbage collector each handle?(senior)
  10. What is the difference between a shallow copy and a deep copy, and when does a shallow copy give surprising results?(junior)
  11. Why do lambdas defined in a loop all return the last value of the loop variable, and how do you fix it?(mid)
  12. Explain *args and **kwargs. Where do they genuinely help, and where do they hurt?(junior)
  13. Why must dictionary keys be immutable (hashable)?(mid)
  14. How are Python dictionaries implemented, and what performance characteristics follow from that?(senior)
  15. Do type hints change how Python runs? How would you introduce typing into a large untyped codebase?(mid)
  16. What is duck typing, and how do Protocols reconcile it with static type checking?(mid)
  17. What do EAFP and LBYL mean, and how expensive are exceptions in Python?(mid)
  18. Why are Python strings immutable, and what does that imply for building a large string in a loop?(junior)
  19. 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)
  20. You fire-and-forget background work with asyncio.create_task and sometimes it silently never finishes — or errors vanish. What is going on?(mid)
  21. A long-running Python worker's memory grows until the container is OOM-killed. Walk through how you would find the leak.(senior)
  22. Your team is standardizing Python tooling for several services. How do you decide between uv, Poetry, and pip-tools?(mid)
  23. Your typed codebase has decorators, and every decorated function loses its signature for mypy/pyright. How do you type a decorator properly?(senior)
  24. Pipeline job: download 50k images over HTTP, CPU-resize each one, upload the results. How do you structure the concurrency?(senior)
  25. Where does pydantic belong in a service's architecture, and what validation patterns keep it from becoming a performance problem?(mid)
  26. 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)
  27. Your service holds millions of small Python objects and memory is the constraint. What are your options for shrinking per-object overhead?(mid)
  28. How does cancellation actually work in asyncio, and what mistakes make timeouts unreliable?(senior)
  29. 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)
  30. 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)
  31. 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)
  32. What does functools.lru_cache buy you, and what are the traps that make it a memory or correctness hazard?(mid)
  33. 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)
  34. 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)
  35. 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)
  36. 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)
  37. Your team standardizes on pydantic v2. Which real-world modeling patterns matter, and what changed from v1 that trips people up?(mid)
  38. 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)