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

Beginner Python interview
Backend engineer interview
Senior Python engineer interview
Data science interview
Machine learning interview
Generative AI interview
Cloud engineer interview
Automation engineer interview

Frequently asked advanced questions

Difference between is and ==?

is = identity (same object); == = value equality via __eq__. Use is only for singletons like None.

Full lesson
How 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 lesson
How does Python manage memory?

Reference counting frees objects at count 0; a generational GC collects cycles; pymalloc handles small objects.

Full lesson
Shallow 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 lesson
How do closures work?

An inner function captures enclosing variables via shared cell objects that outlive the outer call.

Full lesson
What is late binding?

Closures read captured variables at call time, not definition time — the loop-lambda gotcha.

Full lesson
What 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 lesson
How do generators preserve state?

yield suspends the frame, keeping locals and the instruction pointer alive until the next next().

Full lesson
What 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 lesson
How does MRO work?

C3 linearisation orders base classes; super() follows the MRO, enabling cooperative multiple inheritance.

Full lesson
What 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 lesson
Threading vs multiprocessing?

Threads: shared memory, GIL-limited CPU (good for I/O). Processes: own GIL/memory, true CPU parallelism.

Full lesson
What 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 lesson
Why must dict keys be hashable?

The hash locates the bucket; a changing hash would lose the entry, so keys must be immutable/hashable.

Full lesson
How should a production project be structured?

Layered packages (router/service/repository/domain), config at the edges, DI, a clean public API.

Full lesson

Deep-dive interview insights