Role preparation
Python Developer interview questions and answers.
Python runtime behaviour, maintainable services, and automation.
Questions
Technical questions to practise out loud
- 01
What is the Python GIL?
The GIL is a CPython mutex that lets only one thread execute Python bytecode at a time; threads still help I/O, while CPU-bound parallelism usually needs processes or native code that releases it.
Read the full breakdown - 02
When would you use Python generators?
Generators produce values lazily with yield, preserving execution state between iterations; use them for streams or large sequences when materialising every item would waste memory.
Read the full breakdown - 03
Why are mutable default arguments dangerous?
Default arguments are evaluated once when a function is defined, so a mutable list or dict is shared across calls; use None and create a fresh object inside instead.
Read the full breakdown - 04
When would you use asyncio?
asyncio is appropriate for high-concurrency I/O workloads whose libraries expose non-blocking APIs; it does not make CPU-heavy Python code parallel and blocking calls must leave the event loop.
Read the full breakdown - 05
How do Python context managers work?
A context manager brackets resource acquisition and cleanup through __enter__ and __exit__, guaranteeing cleanup on normal completion or exception; with is the standard way to use it.
Read the full breakdown - 06
How do Python decorators work?
A decorator receives a function or class and returns a replacement, usually a wrapper that adds behaviour; functools.wraps preserves metadata and the wrapper must keep the original contract.
Read the full breakdown - 07
How do you manage Python dependencies?
Manage Python dependencies with a declared project file and a reproducible lock, separate runtime from development dependencies, pin deployable environments, and update through tested, reviewable changes.
Read the full breakdown - 08
What is your Python testing strategy?
Use fast unit tests for pure behaviour, integration tests for real boundaries, fixtures with narrow scope, and contract or end-to-end tests only for critical paths; isolate time, network, and mutable global state.
Read the full breakdown - 09
How do you use type hints in Python?
Type hints document and statically check contracts but are not enforced automatically at runtime; use precise unions, protocols, and generics where they clarify APIs, then run a type checker in CI.
Read the full breakdown - 10
How do you profile a slow Python service?
Profile a slow Python service under representative load: separate external latency from CPU and allocation cost, use tracing plus cProfile or py-spy, optimise the measured hot path, then compare against the baseline.
Read the full breakdown