Interview preparation
Prepare for Python interviews
Role-based tracks, the advanced FAQ with layered answers, and coding practice. Every lesson also carries its own interview insights.
Interview tracks by role
Frequently asked advanced questions
Difference between is and ==?
is = identity (same object); == = value equality via __eq__. Use is only for singletons like None.
Full lessonHow do __new__ and __init__ differ?
__new__ creates and returns the instance; __init__ initialises the already-created instance. __new__ matters for immutables and singletons.
What is the GIL?
A mutex letting one thread run CPython bytecode at a time, protecting reference counts. Limits CPU-bound threads, not I/O.
Full lessonHow does Python manage memory?
Reference counting frees objects at count 0; a generational GC collects cycles; pymalloc handles small objects.
Full lessonShallow vs deep copy?
Shallow copies the container but shares nested objects; deep recursively copies everything (copy.deepcopy).
What are mutable default arguments?
Defaults are evaluated once, so a mutable default is shared across calls. Use None and create inside.
Full lessonHow do closures work?
An inner function captures enclosing variables via shared cell objects that outlive the outer call.
Full lessonWhat is late binding?
Closures read captured variables at call time, not definition time — the loop-lambda gotcha.
Full lessonWhat is the LEGB rule?
Name lookup order: Local → Enclosing → Global → Built-in.
How do decorators work?
@dec rebinds name = dec(func); the wrapper (a closure) adds behaviour around the call.
Full lessonHow do generators preserve state?
yield suspends the frame, keeping locals and the instruction pointer alive until the next next().
Full lessonWhat is yield from?
Delegates iteration (and send/throw) to a sub-generator, flattening nested generators.
How do context managers work?
__enter__ sets up, __exit__ tears down even on exception; with guarantees cleanup.
Full lessonHow does MRO work?
C3 linearisation orders base classes; super() follows the MRO, enabling cooperative multiple inheritance.
Full lessonWhat are descriptors?
Objects with __get__/__set__ that control attribute access — the machinery behind property and methods.
What are metaclasses?
The class of a class; type is the default. They customise class creation (registries, validation).
How does AsyncIO / the event loop work?
Coroutines suspend at await and yield to a loop that runs other ready tasks and resumes them on I/O completion.
Full lessonThreading vs multiprocessing?
Threads: shared memory, GIL-limited CPU (good for I/O). Processes: own GIL/memory, true CPU parallelism.
Full lessonWhat makes an object callable?
Defining __call__ — instances then work like functions.
How do hash tables power dicts?
Keys hash to buckets for average O(1) access; collisions resolved by probing + equality.
Full lessonWhy must dict keys be hashable?
The hash locates the bucket; a changing hash would lose the entry, so keys must be immutable/hashable.
Full lessonHow should a production project be structured?
Layered packages (router/service/repository/domain), config at the edges, DI, a clean public API.
Full lessonDeep-dive interview insights
Variables & References
1 model answers · interview importance 4/5
Scope & the LEGB Rule
3 model answers · interview importance 4/5
Closures
2 model answers · interview importance 5/5
Lists & Tuples
3 model answers · interview importance 5/5
Sets & Frozensets
3 model answers · interview importance 4/5
Dictionaries & Hash Tables
1 model answers · interview importance 5/5
Method Resolution Order (MRO)
3 model answers · interview importance 4/5
Decorators
1 model answers · interview importance 5/5
Context Managers & with
3 model answers · interview importance 4/5
Iterators & the Iterator Protocol
3 model answers · interview importance 5/5
Generators & yield
3 model answers · interview importance 5/5
Dict & Set Internals
3 model answers · interview importance 5/5
Reference Counting & Garbage Collection
3 model answers · interview importance 5/5
The Global Interpreter Lock (GIL)
2 model answers · interview importance 5/5
async / await and the Event Loop
1 model answers · interview importance 5/5
Tasks, gather & Concurrency
3 model answers · interview importance 5/5
Threading vs Multiprocessing
3 model answers · interview importance 5/5
Custom Exceptions & Error Design
3 model answers · interview importance 4/5
Protocols & Structural Typing
3 model answers · interview importance 4/5