All specialtiesTechnology · Job interview

Python

Python interviews mix language details with practical habits. Practise explaining each idea in short spoken sentences, with one small example.

Words → phrases → sentences → speaking

Try SpeakRole ↗
Job interviewPython
V

When would you choose Python over a statically typed language?

0:18
Interviewer question

Python

Python interviewers like to ask about things that look simple but have a reason underneath: why a tuple can be a dictionary key, what a generator really does, and why threads behave differently from other languages. A good answer explains the mechanism, not only the rule.

Use the same shape for every answer: a one-sentence definition, a short example, and a note about when you would use it in a real project. Where the behaviour depends on the version of Python, say so, and say which version you used.

  • ✓Words → phrases → sentences → speaking
  • ✓Answer meaning
  • ✓Language

Common questions and sample answers

What is the difference between a list and a tuple, and when would you use each?

What the interviewer wants to hear. Mutability, hashability as a consequence, shallow immutability, and a choice made by meaning, not by speed.

Sample answer to practise aloud

Both are ordered sequences. The main difference is that a list is mutable and a tuple is immutable. I can change, add or remove items in a list, but not in a tuple. Because of this, a tuple of immutable items is hashable, so it can be a dictionary key or a set member, and a list cannot. I use a list for a collection that grows or changes, like a list of results. I use a tuple for a fixed record, like coordinates or a returned pair of values. Remember that immutability is shallow: a tuple that contains a list can still change that list. I choose by meaning, not by speed.

What is a generator, and why would you use one?

What the interviewer wants to hear. Lazy evaluation with yield, memory savings, a link to the iterator protocol, and the one-time-use limit.

Sample answer to practise aloud

A generator is a function that uses yield to produce values one at a time instead of returning a full list. It keeps its state between calls and computes each value only when it is requested. This is lazy evaluation, and it saves memory: I can process a very large file line by line without loading all of it. Under the hood, it follows the iterator protocol, with the special methods dunder-iter and dunder-next, which a for loop calls for me. There is also a short syntax called a generator expression, with round brackets. The limit is that a generator can be used only once. After it is exhausted, I must create a new one.

What is the GIL, and how do you handle concurrency in Python?

What the interviewer wants to hear. What the lock does in CPython, the difference between I/O-bound and CPU-bound work, and the right tool for each.

Sample answer to practise aloud

The GIL, or global interpreter lock, is a lock in the standard CPython interpreter. It allows only one thread to run Python bytecode at a time. So threads do not give real parallelism for CPU-heavy work in pure Python. But for I/O-bound work, like network calls, threads and asyncio work well, because the lock is released while the program waits. For CPU-bound work, I use multiprocessing, where each process has its own interpreter, or I move the heavy part to a library with native code, such as NumPy. Newer Python versions are adding experimental free-threaded builds, but I would check the current status before relying on that.

What is a decorator, and how would you write one?

What the interviewer wants to hear. Functions as first-class objects, the wrapping idea, real use cases, and the habit of using functools.wraps.

Sample answer to practise aloud

A decorator is a function that takes another function and returns a new function, usually one that wraps the original with extra behaviour. The syntax with the at sign is only a shortcut: decorating a function means passing it to the decorator and assigning the result to the same name. This works because functions are first-class objects in Python. I use decorators for cross-cutting things like logging, timing, caching, retries and access checks. A good habit is to use functools.wraps inside the decorator, so the wrapped function keeps its name and its documentation. A decorator with its own arguments needs one more level: a function that returns the decorator.

How do you keep a Python project reproducible and maintainable?

What the interviewer wants to hear. Virtual environments, pinned dependencies, and the role of type hints and a static checker in a team.

Sample answer to practise aloud

I give every project its own virtual environment, so its dependencies do not conflict with other projects or with the system Python. I create it with the built-in venv module, or with a tool such as Poetry or uv, and I never install project packages globally. I pin the dependency versions in a lock file or a requirements file, so a colleague and the CI server get exactly the same environment. For type hints, I add annotations to function signatures and run a checker such as mypy or pyright in CI. Python does not enforce the hints at runtime, but the checker finds many mistakes before the code runs. It also makes the code easier to read.

How to say the key terms

Python
PY-thon (first part like "pie")
tuple
TUP-ul or TOO-pul
mutable
MYOO-tuh-bul
dunder
DUN-der (short for "double underscore")
generator
JEN-uh-ray-ter
decorator
DEK-uh-ray-ter
GIL
gil (hard "g"), or say G-I-L
venv
VEE-env

Useful phrases for answering

  • In Python, everything is an object.
  • It depends on whether the work is I/O-bound or CPU-bound.
  • A tuple of immutable items can be a dictionary key.
  • I would use a generator here to save memory.
  • That is a convention in Python, not a rule of the language.
  • I would check the documentation for the current behaviour.
  • In practice, I would pin the dependencies.

Common mistakes to avoid

  • Saying "Python is slow" and stopping. Explain where the time goes, CPU or waiting, and what you do: profile first, choose the right data structure, and move hot code to native libraries.
  • Saying "the GIL means Python has no threads" or "threads are useless". Threads still help with I/O-bound work. The limit is parallel CPU work in pure Python.
  • Writing a function with a default list argument and not knowing the problem. The default value is created once, so it is shared between calls. Use None as the default and create the list inside the function.
  • Saying "I am working with Python since five years". Use the present perfect with "for": "I have worked with Python for five years". Use "since" only with a starting point, like "since 2019".
  • Calling a list "an array". In Python, an array is a separate type from the standard library. Say "list" or "sequence" so that the interviewer knows what you mean.

Frequently asked questions

Which Python version should I mention?

The one your last project used, and one feature that you liked, for example type hints, dataclasses or structural pattern matching in recent versions. Do not claim features of versions that you have not used. Saying "I would check the release notes" is better than a guess.

Do I need to know asyncio?

For backend and data-service roles, know the basics: coroutines, the event loop, await, when it helps (many network waits) and when it does not (CPU-heavy work). One real example from your work is more valuable than a long definition.

Will I write Python code during the interview?

Often, yes: a small function or a data task. Say your plan first, mention edge cases such as empty input, and use the built-in tools, like enumerate, zip, comprehensions and the collections module. At the end, say the time and memory cost of your solution.

Reading an answer is not the same as saying it. Practise each question out loud, then compare the meaning and the language of your own answer.

Try SpeakRole ↗

Other topics in this area