Python · 24 concepts
Python
The Python language as interviews ask it: the data model, OOP and typing, concurrency, performance, coding tasks and running Python in production.
Asked in these mock interviews
Part 1 · 4 concepts
Core data model
- 01
Mutable and immutable types, and what can be a dict key
A name points to an object. Some objects can change in place (list, dict, set) and some cannot (int, str, tuple). Dict keys must be hashable, so a list cannot be a key…
- 02
Default arguments, copies and changing a list while looping
Default values are built once, when def runs, so a mutable default is shared by every call. A plain assignment copies nothing, a shallow copy shares the inner objects…
- 03
is versus ==, and how arguments work
is checks that two names point to the same object, == checks equality through eq. Function parameters can be positional-only, normal, *args, keyword-only or **kwargs…
- 04
Text, bytes, encodings and money with Decimal
str is Unicode text and bytes is raw data, so reading a file needs an encoding. Money needs Decimal (or whole paise), because floats are binary and built-in round()…
Part 2 · 5 concepts
Functions and flow
- 05
Iterators, generators and lazy pipelines
A for loop calls iter() once and next() until StopIteration. A generator is an iterator made with yield, so it is lazy and can be used only once, which lets a program…
- 06
Closures, LEGB and late binding
Python looks up a name in Local, Enclosing, Global, Built-in order. A closure keeps the variable, not its value, so a lambda made in a loop sees the last value, and…
- 07
Decorators and writing a retry decorator
A decorator is a function that takes a function and returns a replacement. @d above def f means f = d(f), run once when the function is defined. A decorator with…
- 08
The with statement and context managers
with calls enter first and always calls exit at the end, even when the block raises or returns. You can write a context manager as a class or with…
- 09
try, except, else, finally and reviewing error handling
The first matching except runs, else runs only when nothing was raised, and finally always runs. Swallowing errors with except Exception: pass hides bugs and loses…
Part 3 · 4 concepts
Classes and typing
- 10
Class attributes, classmethods and super() with mixins
Instance attributes live on each object and class attributes are shared. super() means the next class in the MRO, not the parent, which matters for mixins and for…
- 11
Dunder methods, dataclasses, Pydantic and slots
Dunder methods are the hooks Python calls for you. Defining eq removes hash unless you define it again. Dataclasses, Pydantic models and attrs each fit a different…
- 12
Properties, descriptors and metaclasses
A property runs code on get, set or delete while callers still write obj.x. Underneath it is a descriptor, and the same idea powers methods, ORMs and Pydantic…
- 13
ABC or Protocol, and adding type checking to a large codebase
An abstract base class needs inheritance, a Protocol only needs matching methods. Type hints are not checked at runtime, so a team adds a type checker step by step and…
Part 4 · 4 concepts
Concurrency
- 14
The GIL and thread safety
The Global Interpreter Lock lets one thread run Python bytecode at a time in a standard CPython process. It helps threads with I/O but does not make your code…
- 15
How asyncio works, and a blocked event loop
An async def call returns a coroutine, and the event loop runs tasks on one thread, switching at each await. One blocking call in a coroutine stops every request in…
- 16
Tasks, gather, TaskGroup and limiting concurrency
Tasks that nobody holds or awaits can vanish and hide errors. gather does not cancel the others when one fails, a TaskGroup does, and any large fan-out needs a limit on…
- 17
Threads, processes, asyncio and free-threading: which one and why
I/O-bound work uses asyncio or threads, CPU-bound pure Python uses processes, and futures hide errors until you read them. Python 3.14 changed how worker processes…
Part 5 · 4 concepts
Performance and memory
- 18
How Python frees memory, and finding leaks
CPython frees an object when its reference count reaches zero, and a cyclic garbage collector handles cycles. A leak is memory that grows with work and never levels…
- 19
Profiling a slow program and a slow start
Measure before you change code. Compare wall time with CPU time, use a profiler to find the biggest cost, and fix the algorithm before micro-tuning. Slow start-up…
- 20
Choosing a data structure, and vectorising loops
The right built-in structure often turns a slow program into a fast one: a set for lookups, a deque for queues, a heap for top N, a Counter for counting. For big…
- 21
Caching: functools, an LRU cache and its traps
cache and lru_cache save the result of a pure function with hashable arguments. In a long-running service they can keep objects alive, return shared mutable results and…
Part 6 · 3 concepts
Python in production
- 22
Lock files, uv, packaging and upgrading Python
A service locks every dependency, including transitive ones. A library declares ranges. Teams choose pip, Poetry or uv, publish internal packages to a private index…
- 23
Reliable pytest suites and mocking in the right place
Flaky tests usually share state, and a mock only works when you patch the name where it is looked up. Fixtures, monkeypatch and dependency injection keep tests…
- 24
Running scripts reliably, logging failures and never unpickling untrusted data
A job needs the right interpreter and environment, logs that show a traceback and a record id, a non-zero exit code on failure, and no code execution from files that…
Your first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.