All skill tracks
languages field guide
Python
Data model, iterators and generators, concurrency and the GIL, packaging, and profiling for Python interviews.
4 difficulty sections16 modules4 lessons4595 min
16
Modules
4/128
Lessons written
4595 min
Total read time
4
Difficulty sections
Cheat sheet: Python at a glance

128 of 4 lessons
- 1What actually happens between typing `python app.py` and your first line of code running?Basicconceptual35 minIn writing
- 2What does assignment actually do in Python, and why is `b = a` not a copy?Basicconceptual30 minIn writing
- 3When should you use `is` instead of `==`, and why does `is` sometimes appear to work for small integers?Basicconceptual30 minIn writing
- 4Which built-in types are immutable, and how does that change how you pass them between functions?Intermediatepractical40 minIn writing
- 5A helper mutates a nested dict the caller passed in and the caller sees the change. How do `copy.copy` and `copy.deepcopy` differ, and which one fixes this?Intermediatetroubleshooting40 minIn writing
- 6How does CPython reclaim memory, and what does the cyclic collector do that reference counting cannot?Advancedconceptual45 minIn writing
- 7Explain to a Java developer why Python has no primitive types, and what that costs you at runtime.Scenarioscenario25 minIn writing
- 8Check your understanding of the interpreter, names, identity, mutability, and garbage collection.Basicconceptual15 minIn writing
- 9How do you decide between a list, tuple, set, and dict for a given piece of data?Basicconceptual35 minIn writing
- 10What are the average-case costs of membership tests, appends, and inserts for list, set, and dict?Intermediateconceptual40 minIn writing
- 11What makes an object usable as a dict key, and what breaks if you mutate a key after inserting it?Intermediateconceptual40 minIn writing
- 12How does slicing work, and what does `items[::-1]` cost compared to `reversed(items)`?Basicpractical30 minIn writing
- 13When would you reach for `defaultdict`, `Counter`, `deque`, or `namedtuple` instead of a plain dict or list?Intermediatepractical45 minIn writing
- 14How do you sort a list of records by two fields with opposite directions, and what does `sorted` guarantee about ties?Intermediatepractical40 minIn writing
- 15You need to keep the 100 most recent events per user across millions of users. Which structures do you choose and why?Scenariodesign25 minIn writing
- 16Check your understanding of container choice, complexity, hashing, and the collections module.Intermediateconceptual15 minIn writing
- 17What is the difference between `str` and `bytes`, and where in a program should encoding and decoding happen?Basicconceptual35 minIn writing
- 18A file reads fine on your Mac and raises `UnicodeDecodeError` in production. How do you diagnose and fix it?Intermediatetroubleshooting40 minIn writing
- 19How do f-strings compare to `%`, `str.format`, and `Template`, and when is an f-string the wrong choice?Basicpractical35 minIn writing
- 20Why is building a string with `+=` in a loop a performance problem, and what do you do instead?Intermediatepractical35 minIn writing
- 21When is a regular expression the right tool for parsing text, and when does it become a maintenance liability?Intermediatepractical45 minIn writing
- 22Two user names look identical on screen but compare unequal. How do you explain and fix it?Advancedtroubleshooting45 minIn writing
- 23A CSV import garbles accented names for some customers only. Walk through your diagnosis.Scenariotroubleshooting25 minIn writing
- 24Check your understanding of text versus bytes, encodings, formatting, and string performance.Intermediateconceptual15 minIn writing
- 25Which values are falsy in Python, and why is `if items:` different from `if items is not None:`?Basicconceptual30 minIn writing
- 26What does the `else` clause on a `for` loop do, and when is it actually useful?Intermediateconceptual30 minIn writing
- 27When does a list comprehension read better than a loop, and when have you gone too far?Basicpractical40 minIn writing
- 28How do dict and set comprehensions change the way you reshape data, and what are their failure modes?Intermediatepractical35 minIn writing
- 29Where does the walrus operator earn its keep, and where does it just hide work?Intermediatepractical35 minIn writing
- 30What can `match`/`case` express that an if/elif chain cannot, and when would you still use if/elif?Advancedpractical45 minIn writing
- 31You are handed a 200-line function of nested ifs that classifies events. How do you restructure it?Scenariodesign25 minIn writing
- 32Check your understanding of truthiness, loop constructs, comprehensions, and pattern matching.Intermediateconceptual15 minIn writing
- 33Walk through `*args`, `**kwargs`, keyword-only, and positional-only parameters, and when each belongs in an API.Basicconceptual40 minIn writing
- 34Why is using a mutable object as a default argument value a bug waiting to happen in Python, and what's the correct pattern?Intermediatepractical5 min
- 35How does Python resolve a name inside a function, and what do `global` and `nonlocal` actually change?Intermediateconceptual40 minIn writing
- 36What is a closure, and why does a loop that builds lambdas often capture the wrong value?Intermediatepractical45 minIn writing
- 37What does it mean that functions are first-class objects, and how does that show up in everyday Python?Basicpractical35 minIn writing
- 38A recursive tree walk raises `RecursionError` on real data. What are your options?Advancedtroubleshooting40 minIn writing
- 39Design the signature of a public helper that must stay backward compatible as options accumulate.Scenariodesign25 minIn writing
- 40Check your understanding of argument passing, defaults, scope, and closures.Intermediateconceptual15 minIn writing
- 41What does a `for` loop actually call under the hood, and how do `__iter__` and `__next__` fit together?Basicconceptual35 minIn writing
- 42What does `yield` change about how a function runs, and when is a generator the right return type?Intermediatepractical40 minIn writing
- 43When would you pass a generator expression instead of a list comprehension, and what do you give up?Intermediatepractical35 minIn writing
- 44How would you process a 50GB log file that will never fit in memory?Advancedpractical45 minIn writing
- 45Which itertools functions do you actually reach for, and what problem does each solve?Intermediatepractical45 minIn writing
- 46What does `yield from` do beyond saving a loop, and how does a generator receive values with `send`?Advancedconceptual45 minIn writing
- 47Design a streaming pipeline that reads, filters, enriches, and batches records without loading them all.Scenariodesign25 minIn writing
- 48Check your understanding of the iterator protocol, generators, laziness, and itertools.Advancedconceptual15 minIn writing
- 49What is the difference between a class attribute and an instance attribute, and when does that difference bite?Basicconceptual35 minIn writing
- 50Which dunder methods do you implement to make a class behave like a real Python object, and in what order of priority?Intermediatepractical45 minIn writing
- 51You added `__eq__` to a class and now instances cannot be put in a set. What happened?Advancedtroubleshooting40 minIn writing
- 52When does inheritance genuinely beat composition, and how do you tell you have chosen wrong?Advanceddesign45 minIn writing
- 53How does Python resolve `super()` with multiple inheritance, and what is the MRO actually computing?Advancedconceptual45 minIn writing
- 54When do you use a dataclass, a NamedTuple, or a plain class, and what do `frozen=True` and `slots=True` buy you?Intermediatepractical45 minIn writing
- 55Model a payments domain with three payment methods that share validation but differ in settlement. How do you structure it?Scenariodesign25 minIn writing
- 56Check your understanding of attributes, dunder methods, inheritance, the MRO, and dataclasses.Advancedconceptual15 minIn writing
- 57Write a decorator that times a function, and explain what `@` actually does at import time.Intermediateconceptual40 minIn writing
- 58After adding a decorator, help output and tracebacks show the wrapper's name. How do you fix it and why does it matter?Intermediatetroubleshooting30 minIn writing
- 59How do you write a decorator that takes arguments, and why does it need an extra layer?Advancedpractical45 minIn writing
- 60When is `functools.lru_cache` the right cache, and when is it a memory leak in disguise?Intermediatepractical40 minIn writing
- 61How does `@property` work, and what is the descriptor protocol underneath it?Advancedconceptual50 minIn writing
- 62When do you use `@classmethod` versus `@staticmethod`, and what does each actually receive?Intermediateconceptual35 minIn writing
- 63Design a retry decorator for flaky network calls that is safe to apply to any function in the codebase.Scenariodesign25 minIn writing
- 64Check your understanding of decorators, wraps, caching, properties, and descriptors.Advancedconceptual15 minIn writing
- 65How is Python's exception hierarchy organized, and why is `except Exception` different from `except BaseException`?Basicconceptual35 minIn writing
- 66What belongs in `else` versus `finally`, and what happens if `finally` returns?Intermediateconceptual35 minIn writing
- 67When is a custom exception class worth defining, and how do you design one other people will catch correctly?Intermediatedesign40 minIn writing
- 68What is the difference between `raise ... from err` and a bare `raise`, and why does chaining matter in production logs?Advancedpractical40 minIn writing
- 69How do you write a context manager two different ways, and when does `contextlib.contextmanager` beat a class?Intermediatepractical45 minIn writing
- 70Explain EAFP versus LBYL and pick one for a file-processing routine that runs concurrently.Advanceddesign40 minIn writing
- 71A service swallows errors with a bare `except:` and now failures show up as empty responses. How do you unwind that?Scenariotroubleshooting25 minIn writing
- 72Check your understanding of the exception hierarchy, cleanup, chaining, and context managers.Intermediateconceptual15 minIn writing
- 73What do type hints actually do at runtime, and what value do they add if the interpreter ignores them?Basicconceptual35 minIn writing
- 74How do you type a value that may be missing, and why is `Optional[str]` different from a default of `None`?Intermediatepractical35 minIn writing
- 75How do you type a function that returns whatever type it was given, and what changed with the 3.12 generics syntax?Advancedpractical50 minIn writing
- 76When is a `Protocol` a better contract than an abstract base class?Advanceddesign45 minIn writing
- 77How would you introduce mypy to a large untyped codebase without stopping feature work?Intermediatepractical45 minIn writing
- 78Type hints do not validate untrusted input. Where do you put real validation, and what do you use?Advanceddesign45 minIn writing
- 79An interviewer asks whether type hints are worth it on a small team. Make the case honestly, including the costs.Scenariodesign25 minIn writing
- 80Check your understanding of hints, Optional, generics, protocols, and static analysis tooling.Advancedconceptual15 minIn writing
- 81What does `import x` actually do, and how does Python decide which file to load?Intermediateconceptual40 minIn writing
- 82The same script works with `python -m pkg.main` and fails with `python pkg/main.py`. Why?Intermediatetroubleshooting40 minIn writing
- 83Two modules import each other and one raises `ImportError` at startup. How do you fix it properly?Advancedtroubleshooting40 minIn writing
- 84Why does every project get its own virtual environment, and what does `venv` actually change?Basicpractical30 minIn writing
- 85What is the difference between declaring dependencies and locking them, and why do you need both?Intermediatepractical40 minIn writing
- 86How do you turn a folder of scripts into an installable package with `pyproject.toml`?Advancedpractical50 minIn writing
- 87Design the repo and release layout for an internal library three teams will depend on.Scenariodesign25 minIn writing
- 88Check your understanding of imports, environments, dependency locking, and packaging.Intermediateconceptual15 minIn writing
- 89What is the Global Interpreter Lock (GIL), and why doesn't adding more threads speed up a CPU-bound Python program?Basicconceptual5 min
- 90What kinds of work actually get faster with `threading`, and how do you size a thread pool?Intermediatepractical40 minIn writing
- 91Two threads increment the same counter and the total is wrong. Explain the race and the fixes.Advancedtroubleshooting45 minIn writing
- 92How does `multiprocessing` sidestep the GIL, and what does the process boundary cost you?Advancedpractical45 minIn writing
- 93How does `concurrent.futures` unify threads and processes, and how do you handle a task that raises?Intermediatepractical40 minIn writing
- 94Design a bounded producer/consumer pipeline with `queue.Queue` and explain what backpressure does for you.Advanceddesign45 minIn writing
- 95A nightly job fetches 10,000 URLs and then resizes every downloaded image. How do you parallelize each half?Scenariodesign25 minIn writing
- 96Check your understanding of the GIL, threads, locks, processes, and executor pools.Advancedconceptual15 minIn writing
- 97What does `await` actually do, and why does calling a coroutine without awaiting it do nothing?Intermediateconceptual40 minIn writing
- 98Walk through how the event loop schedules coroutines, and what happens when one blocks.Advancedconceptual45 minIn writing
- 99How do you run ten independent requests concurrently, and why is `TaskGroup` preferred over `gather` in 3.11+?Intermediatepractical45 minIn writing
- 100How do cancellation and `asyncio.timeout` work, and what must your cleanup code do to cooperate?Advancedpractical45 minIn writing
- 101One handler makes a synchronous database call and latency spikes for every request. Explain and fix it.Advancedtroubleshooting45 minIn writing
- 102When would you choose asyncio over threads or multiprocessing for a Python service, and what has to change about the whole codebase to adopt it?Advanceddesign5 min
- 103Design an async worker that consumes a queue with a concurrency cap, retries, and graceful shutdown.Scenariodesign25 minIn writing
- 104Check your understanding of coroutines, the event loop, task groups, cancellation, and blocking calls.Advancedconceptual15 minIn writing
- 105Walk through reading and writing files safely, including text versus binary mode and encoding.Basicpractical35 minIn writing
- 106Why use `pathlib` over `os.path` and string concatenation, and what does it protect you from?Basicpractical30 minIn writing
- 107How do you serialize objects that `json` refuses to encode, and how do you parse untrusted JSON safely?Intermediatepractical40 minIn writing
- 108A CSV import breaks on a row containing a quoted comma. Why does `line.split(",")` fail and what replaces it?Intermediatetroubleshooting35 minIn writing
- 109How do you process a multi-gigabyte file line by line while keeping memory flat?Advancedpractical45 minIn writing
- 110A crash mid-write leaves a truncated data file. How do you make file writes atomic?Advanceddesign45 minIn writing
- 111Design an idempotent import job that ingests a daily 2GB CSV into Postgres and can be safely re-run.Scenariodesign25 minIn writing
- 112Check your understanding of file I/O, pathlib, JSON, CSV, and streaming large files.Intermediateconceptual15 minIn writing
- 113How do you structure a pytest suite, and what makes a test worth keeping?Basicpractical40 minIn writing
- 114How do fixtures work, and how do you choose between function, module, and session scope?Intermediatepractical45 minIn writing
- 115When does `@pytest.mark.parametrize` beat writing separate test functions?Intermediatepractical35 minIn writing
- 116What should you mock, what should you never mock, and why does `patch` need the import path of the user, not the definition?Advancedpractical45 minIn writing
- 117How do you test code that awaits, sleeps, or reads the clock without making the suite slow and flaky?Advancedpractical45 minIn writing
- 118A test passes locally and fails one run in ten in CI. How do you find the cause?Advancedtroubleshooting45 minIn writing
- 119Design the test strategy for a service that calls a paid third-party API. What is unit, what is integration, what is neither?Scenariodesign25 minIn writing
- 120Check your understanding of pytest structure, fixtures, parametrization, and mocking.Intermediateconceptual15 minIn writing
- 121A script takes 40 seconds and nobody knows why. How do you find the hot spot with `cProfile` and `timeit`?Intermediatepractical45 minIn writing
- 122You found the hot loop. What are your options in order, before rewriting anything in C?Advancedpractical45 minIn writing
- 123How do you measure what a Python process is actually holding in memory, and which tools tell you what?Advancedpractical45 minIn writing
- 124A long-running Python worker process's memory usage climbs steadily over days until it's OOM-killed and restarted. How would you find the leak?Scenarioscenario5 min
- 125How do you configure logging for a production service, and why is `print` not a substitute?Intermediatedesign40 minIn writing
- 126A bug reproduces only in production. What can you use beyond adding log lines?Advancedtroubleshooting45 minIn writing
- 127Latency on a Python API doubled after a deploy with no obvious code cause. Walk through your investigation.Scenariotroubleshooting25 minIn writing
- 128Capstone: take a small Python service end to end — profile it, fix its slowest path, harden its error handling, add tests, and write the runbook you would hand to on-call.Scenariodesign240 minIn writing