Python Interview Questions for Experienced Developers (2026)
By Preeti Verma
For an experienced Python role, interviewers are less interested in whether you know list comprehension syntax and more interested in whether you understand what is happening underneath common patterns. Here are the questions that come up most, with what a strong answer covers.
The GIL and concurrency
What is the GIL, and why does it matter? The Global Interpreter Lock allows only one thread to execute Python bytecode at a time, even on a multi-core machine. It means threading does not speed up CPU-bound work, though it is still useful for I/O-bound work (network calls, file reads) where a thread releases the GIL while waiting.
If threading does not help CPU-bound work, what does? The multiprocessing module, which runs separate processes each with their own interpreter and GIL, so they run in true parallel on separate cores. The cost is that processes do not share memory directly, so you pay for serialization to pass data between them.
When would you use asyncio instead of threads? For I/O-bound work with a very large number of concurrent operations, such as thousands of network calls, where the overhead of a thread per operation would be too high. asyncio runs on a single thread with an event loop, and code must be written to cooperate (await) rather than block.
Mutability and a classic trap
What is wrong with def add_item(item, items=[]):? The default list is created once, when the function is defined, not each time it is called. Every call that relies on the default shares the same list, so items silently accumulate across calls. The fix is items=None, then if items is None: items = [] inside the function.
What is the difference between a shallow copy and a deep copy? A shallow copy creates a new outer object but keeps references to the same nested objects, so mutating a nested list inside the copy also changes the original. A deep copy recursively copies everything, so nothing is shared.
Generators and iterators
What is a generator, and why use one instead of returning a list? A generator produces values lazily, one at a time, using yield, instead of building the whole result in memory. This matters when processing something large: a generator that reads a huge file line by line uses constant memory, while returning a full list does not.
What is the difference between an iterator and an iterable? An iterable has an __iter__ method and can produce an iterator; an iterator has both __iter__ and __next__ and tracks its own position. A list is iterable but is not itself an iterator; calling iter() on it gives you one.
Decorators
Explain what a decorator actually does. A decorator is a function that takes a function and returns a (usually wrapped) function, letting you add behavior (logging, timing, caching, access checks) without changing the original function's code. @decorator above a function is shorthand for func = decorator(func).
Write a simple timing decorator. A good answer shows a function that takes func, defines an inner wrapper(*args, **kwargs) that times the call and returns the result, and returns wrapper, plus mentions functools.wraps to preserve the original function's name and docstring.
Object model
What is the difference between __str__ and __repr__? __str__ is meant to be readable, for end users (used by print()). __repr__ is meant to be unambiguous, ideally something that could recreate the object, and is what you see in a debugger or a list's repr.
What are *args and kwargs? *args collects extra positional arguments into a tuple; kwargs collects extra keyword arguments into a dict. They let a function accept a flexible number of arguments, and are common in decorators and wrapper functions that need to pass arguments through unchanged.
What is duck typing, and how does Python use it? "If it walks like a duck and quacks like a duck, treat it as a duck": Python usually cares whether an object supports the operations you use (like iteration or a .read() method) rather than its declared type. This is why many Python functions accept "any file-like object" rather than requiring a specific class.
Exceptions and context managers
What does the with statement do? It uses a context manager (an object with __enter__ and __exit__) to guarantee cleanup, such as closing a file, even if an exception happens inside the block. It is the Pythonic replacement for a manual try/finally.
How would you write your own context manager? Either a class with __enter__ and __exit__, or a generator function decorated with @contextlib.contextmanager that yields once, with setup before the yield and cleanup after (in a try/finally if the cleanup must run even on exception).
How to prepare
Expect at least one live-coding question mixed in with these concept questions, often something like flattening a nested list, deduplicating while preserving order, or a small class design. Practise explaining trade-offs out loud as you write, since most interviewers are grading your reasoning as much as your final code. Our AI Coach can explain any of these concepts in plain English if one still feels unclear.