Core concepts
- GIL — why threads don't parallelize CPU-bound Python; use multiprocessing instead. — Python glossary: GIL
- Decorators — functions wrapping functions; used in Flask/FastAPI routes. — Python glossary: decorator
- Iterators & generators —
yieldfor lazy sequences and streaming. — Python docs: Generators - Context managers —
with open(...) as fpattern via__enter__/__exit__. — Python docs: Context managers - Mutable default args — classic bug; use
Nonesentinel pattern. — Python docs: Default argument values
Concept videos
YouTube lessons for these topics. On a large screen they open in the reading panel next to the roadmap, same as the article links on each core concept.
- GIL — Python GIL Explained (Tech With Tim)
- Decorators — Python Decorators (Corey Schafer)
- Generators — Python Generators (Corey Schafer)
- Mutable defaults — Mutable Default Arguments (Corey Schafer)
Explanation
Python interviews probe whether you understand objects, execution model, and idioms — not memorized trivia.
GIL
The Global Interpreter Lock means one thread executes Python bytecode at a time in CPython. Threads still help I/O-bound work; CPU-bound parallelism needs multiprocessing or native code. Explain like a single-lane bridge: many cars, one lane for Python bytecode.
Decorators
Decorators wrap functions to add logging, auth, or timing without changing call sites. @app.get("/") in FastAPI is decorator sugar. Implementation-wise: a function that takes a function and returns a new callable.
Iterators & generators
Iterators produce items lazily — memory friendly for large files or streams. Generators (yield) pause and resume state automatically. They power pipeline-style data processing and async-friendly patterns.
Context managers
with guarantees setup/teardown — files close, locks release, even on exceptions. Implement with __enter__/__exit__ or @contextmanager for reusable resource blocks.
Mutable default args
Default values bind once at function definition. Mutable defaults ([], {}) share state across calls — the famous “sticky list” bug. Use None and create fresh objects inside the function body.
What Is It?
This page gathers common Python-specific interview themes: data model, comprehensions, context managers, and concurrency limits.
Focus on explaining object behavior (__repr__, mutability) and standard library patterns.
Link answers to code you have run, not blog trivia.
Why Should I Care?
Backend and ML-adjacent roles still filter on Python fundamentals even when job titles mention AI.
Decorators and context managers appear in FastAPI dependencies and pytest fixtures.
Real World Analogy
Python interviews are open-book cooking tests — they want to see you choose the right utensil (list vs generator), not memorize every recipe.
Visual Mental Model
GIL | decorators | iterators | data modelBeginner Explanation
Review GIL, decorators, iterators, dunder methods, and async basics. Explain with tiny examples you can type live.
Smallest Possible Example
squares = [x * x for x in range(3)]
g = (x * x for x in range(3))
print(squares, next(g))Common Mistakes
❌ Claiming the GIL makes Python useless for concurrency.
It limits CPU threads, not I/O concurrency or multiprocessing.
❌ Confusing @staticmethod and @classmethod purposes.
classmethod gets cls; staticmethod is a namespaced function.
❌ Not knowing list vs generator tradeoffs.
Memory and laziness differ — common follow-up question.
Real Project Example
Spotify backend interviews include Python data structure questions.
Bloomberg uses Python heavily — iterator and memory questions show up often.
Build This Mini Project
Implement a context manager with and without @contextmanager, and explain both in a 60-second voice note.
Interview Question
What is the GIL?
The Global Interpreter Lock is a mutex in CPython preventing multiple threads from executing Python bytecode at once. It simplifies memory management but limits CPU parallelism in threads; processes sidestep it.
Key Takeaways
- Know data model basics.
- Generators save memory.
- GIL affects CPU threads, not all concurrency.
- Practice short live-coded examples.
Resources
The 60-second story
The interviewer slides a coffee across the table and asks why your threads did not make the report faster. The honest answer is the kitchen has one chef’s knife even when you hire extra cooks. The GIL is that knife in standard CPython. Threads can wait on the oven (I/O) and look busy. They cannot all chop at once. CPU-bound work wants processes, separate kitchens, not more cooks fighting over one knife.
Decorators are a jacket you put on a function. The function is still the person. The jacket adds “log this,” “require auth,” or “this route is GET /orders.” Flask and FastAPI live in jackets. If you can say “a function that takes a function and returns a function,” you have survived the definition round.
Generators are a baker who hands you one bun at a time instead of filling the counter with a thousand. yield pauses the baker between buns. You use that when the full tray would not fit in memory, or when you are streaming rows from a database and do not want the whole year in a list.
A context manager is the shop rule: unlock the door, do the work, lock it even if you trip. with open(path) as f is that rule for files. __enter__ unlocks. __exit__ locks, including on the way out through an exception. Interviews ask because leaked files and leaked locks are how demos become incidents.
Mutable defaults are the shared pastry plate from the functions page. def f(items=[]) builds one list and every call keeps writing on it. The fix is None and a new list inside. If you tell that story with a straight face, they believe you have been paged at night.
Map the questions.
- GIL = one knife, many cooks, chopping does not parallelize.
- A decorator = a jacket around a function.
- A generator = one bun at a time.
with= unlock and always lock again.- Mutable default = one plate for every customer.
def accumulate(item, items=None):
if items is None:
items = []
items.append(item)
return itemsThese questions last because they are production footguns, not because they are cute. The GIL explains a performance graph. The default argument explains a test that passes alone and fails in a suite. The generator explains a memory chart that went flat after you stopped building a giant list.
Mental model: one knife, a jacket, a single bun, a door that locks itself. If you can draw those four on a napkin, you can answer the usual Python interview without reciting a glossary.
Practice the mutable-default snippet until the None check feels obvious. Then explain the GIL in one breath: threads overlap waiting, processes overlap chopping.

