Skip to content
Resume Studioby M2Toolkit

10 role-specific questions

Python Developer Interview Questions & Answers

Python interviews test fluency with the language — data structures, generators, decorators, common gotchas — plus concurrency, testing and a web framework such as Django, Flask or FastAPI.

Free, no sign-up. 93 questions in this role's practice pool, including behavioural, HR and situational questions.

Python interview questions

Core Python, data structures, generators, decorators, the GIL, async, packaging and web frameworks.

  1. 1.

    Compare lists, tuples, sets and dictionaries in Python. When would you use each?

    BeginnerTechnical

    What the interviewer is evaluating

    Choosing the right data structure.

    Key points a strong answer covers

    • list. Lists are ordered and mutable.
    • tuple. Tuples are immutable — good for fixed records and dictionary keys.
    • set. Sets hold unique items with fast membership tests.
    • dict. Dicts map keys to values with O(1) average lookups (insertion-ordered since 3.7).
    • Complexity. Membership: O(1) average in sets/dicts vs O(n) in lists.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Checking membership in a large list inside a loop.
    • Using a list where a tuple signals intent better.

    Likely follow-up questions

    • Why can a tuple be a dictionary key but a list can't?
    • How would you remove duplicates while keeping order?
    Example strong answer

    A list is an ordered, mutable sequence — my default for collections I'll append to or sort. A tuple is ordered but immutable, which suits fixed records like coordinates and function return values, and because it's hashable (if its contents are) it can be a dict key or set member. A set stores unique items and checks membership in O(1) on average, so it's ideal for de-duplicating or testing 'have I seen this id?' — doing that with a list inside a loop is O(n²). A dict maps keys to values with fast lookups and keeps insertion order since Python 3.7. To de-duplicate while keeping order I use list(dict.fromkeys(items)).

    Practise this question and get feedback
  2. 2.

    What are generators, and why would you use them?

    IntermediateTechnical

    What the interviewer is evaluating

    Memory-efficient iteration.

    Key points a strong answer covers

    • yield. A generator function uses yield to produce values one at a time.
    • Lazy / memory efficient. Values are produced lazily, so large or infinite sequences don't need to fit in memory.
    • Iterator protocol. Generators are iterators — they can be consumed once.
    • Generator expressions / use cases. Generator expressions; reading large files line by line; pipelines.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Trying to iterate a generator twice.
    • Building a huge list just to sum it.

    Likely follow-up questions

    • What's the difference between [x for x in y] and (x for x in y)?
    • What does yield from do?
    Example strong answer

    A generator is a function that uses yield to produce values one at a time. Calling it returns an iterator; each next() runs the function until the next yield, then pauses with its state intact. Because values are produced lazily, you can process huge or even infinite sequences without holding them in memory — reading a 5 GB log file line by line and yielding only the error lines, for example. Generator expressions like sum(x * x for x in numbers) avoid building an intermediate list. They're also nice for pipelines of small steps. A generator can only be consumed once, so iterating it a second time gives nothing.

    Practise this question and get feedback
  3. 3.

    What is a decorator in Python? Write or describe one.

    IntermediateTechnical

    What the interviewer is evaluating

    Understanding first-class functions and closures.

    Key points a strong answer covers

    • Function that wraps a function. A decorator takes a function and returns a new function that wraps it.
    • @ syntax. @decorator is shorthand for func = decorator(func).
    • functools.wraps. functools.wraps preserves the original function's name and docstring.
    • Use cases. Logging, timing, caching (lru_cache), retries, auth checks, route registration.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Forgetting *args and **kwargs in the wrapper.
    • Not using functools.wraps.

    Likely follow-up questions

    • How would you write a decorator that takes arguments, like @retry(times=3)?
    • What does lru_cache do?
    Example strong answer

    A decorator is a function that takes a function and returns a new one, usually wrapping the original to add behaviour before or after it runs. @timer above a function is shorthand for func = timer(func). A timing decorator defines an inner wrapper(*args, **kwargs) that records the time, calls the original with the same arguments, logs how long it took and returns the result; I decorate the wrapper with functools.wraps(func) so the name and docstring survive. Real uses are logging, caching with functools.lru_cache, retries with backoff, permission checks like Django's login_required, and registering routes in Flask or FastAPI. A decorator with arguments, like @retry(times=3), is a function that returns a decorator.

    Practise this question and get feedback
  4. 4.

    What is the GIL, and how does it affect concurrency in Python?

    AdvancedTechnical

    What the interviewer is evaluating

    Choosing between threads, processes and asyncio.

    Key points a strong answer covers

    • One thread executes bytecode. In CPython the GIL lets only one thread execute Python bytecode at a time.
    • I/O-bound threads still help. The GIL is released during I/O, so threads help I/O-bound work.
    • CPU-bound needs processes. For CPU-bound work use multiprocessing or native extensions (NumPy).
    • asyncio. asyncio handles many I/O tasks on one thread.
    • Free-threaded builds. Python 3.13 introduced an optional free-threaded build (experimental).

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Saying Python can't do concurrency at all.
    • Using threads to speed up CPU-bound loops.

    Likely follow-up questions

    • Would threads speed up resizing 1,000 images in pure Python?
    • When would you choose asyncio over threads?
    Example strong answer

    The GIL — Global Interpreter Lock — in CPython lets only one thread execute Python bytecode at a time, which simplifies memory management but limits parallelism. It's released while a thread waits on I/O, so threads still speed up I/O-bound work like making many HTTP requests. For CPU-bound work in pure Python — heavy loops, parsing — threads don't help; I use multiprocessing or a ProcessPoolExecutor, or libraries like NumPy that do the work in C and release the GIL. For lots of concurrent network I/O, asyncio runs thousands of tasks on one thread. Python 3.13 added an optional free-threaded build without the GIL, but it's still experimental and library support varies.

    Practise this question and get feedback
  5. 5.

    Why is using a mutable default argument like def f(items=[]) a bug?

    BeginnerTechnical

    What the interviewer is evaluating

    Awareness of a classic Python gotcha.

    Key points a strong answer covers

    • Evaluated once. Default values are evaluated once, when the function is defined.
    • Shared between calls. The same list is shared by every call, so it accumulates values.
    • Fix with None. Use None as the default and create a new list inside.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Thinking the list is recreated on each call.
    • Not knowing the fix.

    Likely follow-up questions

    • Does the same problem apply to dataclass fields?
    • Can this behaviour ever be useful?
    Example strong answer

    Default argument values are evaluated once, when the function is defined, not each time it's called. So def add(item, items=[]) creates one list that every call shares: the first call returns [1], the next call returns [1, 2], and so on — state leaks between calls. The fix is to use None as a sentinel: def add(item, items=None): if items is None: items = []. The same thing applies to dicts and sets, and dataclasses guard against it by requiring field(default_factory=list). Occasionally people use the behaviour on purpose as a simple cache, but functools.lru_cache is clearer.

    Practise this question and get feedback
  6. 6.

    How does async/await work in Python? When would you use it?

    IntermediateTechnical

    What the interviewer is evaluating

    Understanding asyncio's model and limits.

    Key points a strong answer covers

    • Coroutines & event loop. async def creates coroutines run cooperatively by an event loop.
    • await yields control. await suspends the coroutine so others can run while it waits.
    • Concurrency. asyncio.gather / TaskGroup run many I/O operations concurrently.
    • Blocking calls. A blocking call stalls the whole loop — use async libraries or to_thread.
    • Use cases. High-concurrency I/O: APIs, websockets, crawlers.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Calling requests.get or time.sleep inside async code.
    • Using async for CPU-bound work.

    Likely follow-up questions

    • What happens if one coroutine does a blocking database call?
    • What does asyncio.TaskGroup add over gather?
    Example strong answer

    async def defines a coroutine, and an event loop started with asyncio.run runs coroutines cooperatively on a single thread. When a coroutine hits await on something not ready — a network response — it suspends and the loop runs other coroutines, then resumes it when the data arrives. With asyncio.gather or a TaskGroup, I can fetch hundreds of URLs concurrently. It shines for I/O-heavy work: API servers with FastAPI, websockets, crawlers. The catch is that everything must be non-blocking: calling requests.get or time.sleep inside a coroutine freezes the entire loop, so I use async libraries like httpx, or push blocking work to asyncio.to_thread. It doesn't help CPU-bound work.

    Practise this question and get feedback
  7. 7.

    How do you manage dependencies and environments in Python projects?

    BeginnerTechnical

    What the interviewer is evaluating

    Professional project hygiene.

    Key points a strong answer covers

    • Virtual environments. Each project gets its own virtual environment.
    • Declare dependencies. Dependencies declared in pyproject.toml (or requirements files).
    • Lock versions. A lock file pins exact versions for reproducible builds.
    • Separate dev deps. Dev/test dependencies kept separate.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Installing packages globally.
    • Unpinned dependencies in production.

    Likely follow-up questions

    • What's the difference between pyproject.toml and a lock file?
    • How would you upgrade dependencies safely?
    Example strong answer

    Every project gets its own virtual environment so its packages don't clash with other projects or the system Python. Dependencies are declared in pyproject.toml — with ranges for libraries — and a lock file pins exact versions and hashes so every machine and the CI build install the same thing. These days I use uv or Poetry, which handle the environment, resolution and locking together; on older projects, pip-tools generating a pinned requirements file does the same job. Development dependencies like pytest and ruff are kept separate from runtime ones. I upgrade in small batches with Dependabot or Renovate, letting the test suite catch breaking changes.

    Practise this question and get feedback
  8. 8.

    Compare Django, Flask and FastAPI. Which would you choose for a new project?

    IntermediateTechnical

    What the interviewer is evaluating

    Framework judgement based on requirements.

    Key points a strong answer covers

    • Django batteries included. Django is batteries-included: ORM, admin, auth, migrations.
    • Flask minimal. Flask is minimal and flexible — you choose the pieces.
    • FastAPI typed async APIs. FastAPI is async-first with Pydantic validation and automatic OpenAPI docs.
    • Choosing. Choose by needs: full web apps and admin → Django; typed APIs → FastAPI.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Choosing purely on benchmark speed.
    • Not mentioning the team's experience.

    Likely follow-up questions

    • How does FastAPI use type hints for validation?
    • What would you add to Flask to match Django's features?
    Example strong answer

    Django is batteries-included: an ORM, migrations, authentication, an admin site, forms and templating, with strong conventions — great for a full web application or a back office where the admin alone saves weeks. Flask is a microframework: routing and little else, so you choose the ORM, auth and validation — flexible, but you assemble it yourself. FastAPI is built for APIs: async-first, uses type hints and Pydantic for request validation and serialisation, and generates OpenAPI docs automatically. For a new JSON API or microservice I'd lean to FastAPI; for a content- or admin-heavy product, Django — possibly with Django REST Framework. The team's experience weighs heavily too.

    Practise this question and get feedback
  9. 9.

    How do you test Python code?

    IntermediateTechnical

    What the interviewer is evaluating

    Testing practice and tooling.

    Key points a strong answer covers

    • pytest. pytest is the standard test runner.
    • Fixtures. Fixtures provide reusable setup like a test database or client.
    • Parametrize. @pytest.mark.parametrize covers many cases concisely.
    • Mocking. Mock external services with unittest.mock or monkeypatch.
    • CI / coverage. Run in CI with coverage.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Mocking so much that tests only test the mocks.
    • Tests that hit real external APIs.

    Likely follow-up questions

    • What's the difference between patch and monkeypatch?
    • How would you test code that depends on the current time?
    Example strong answer

    I use pytest. Fixtures handle setup — a test client, a temporary database, sample data — and live in conftest.py so they're shared; their scope controls whether they're rebuilt per test or per session. @pytest.mark.parametrize runs one test over many inputs, which is perfect for edge cases. External services are mocked at the boundary with unittest.mock.patch, monkeypatch, or HTTP-level tools like respx, while my own code runs for real. For time-dependent code I inject a clock or use freezegun. Everything runs in CI with coverage reporting, and I focus coverage on business logic rather than chasing a number.

    Practise this question and get feedback
  10. 10.

    What's the difference between == and is in Python?

    BeginnerTechnical

    What the interviewer is evaluating

    Precision about identity vs equality.

    Key points a strong answer covers

    • == compares values. == compares values (calls __eq__).
    • is compares identity. is checks whether both names refer to the same object.
    • Use is for None. Use is for singletons like None.
    • Interning pitfall. Small ints and some strings are cached, so is can appear to work by accident.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Using is to compare strings or numbers.
    • Writing == None.

    Likely follow-up questions

    • Why might a is b be True for small integers but False for large ones?
    • How would you make a class compare by value?
    Example strong answer

    == checks whether two objects have equal values — it calls __eq__ — while is checks identity: whether both names point to the very same object. Two separate lists [1, 2] are == but not is. The rule is to use is only for singletons like None, True and False — if result is None — and == for everything else. Comparing numbers or strings with is is a bug that sometimes works by accident, because CPython caches small integers from -5 to 256 and interns some strings, so x is 100 can be True while x is 1000 is False.

    Practise this question and get feedback

Behavioural & HR questions you'll also get

These come up in almost every python developer interview. Story questions are best answered with STAR — Situation, Task, Action, Result.

  • Tell me about yourself.

    BeginnerHR

    What the interviewer is evaluating

    Whether you can give a concise, relevant pitch that frames your experience around this job.

    Key points a strong answer covers

    • Present. Start with your current role and what you do.
    • Relevant past. Pick the most relevant past experience.
    • Strength / achievement. Include one strength or achievement with evidence.
    • Why this role. Finish with why this role is the next step.

    Suggested answer structure

    1. Present — your current role in one or two sentences.
    2. Past — the experience most relevant to this job.
    3. Proof — one achievement or strength with evidence.
    4. Future — why this role is the logical next step.

    Common mistakes

    • Reciting your whole CV chronologically.
    • Personal life story unrelated to the job.
    • Going over two minutes.

    Likely follow-up questions

    • Why are you looking to leave your current role?
    • What would your manager say is your biggest strength?
    Example strong answer

    I'm a front-end developer with four years' experience, currently at a fintech start-up where I build the customer dashboard in React and TypeScript. Before that I spent two years at an agency building e-commerce sites, which taught me to work fast with lots of different clients. The thing I'm proudest of recently is leading our move to a shared component library, which cut the time to build new screens by about a third. I'm now looking for a role where I can work on a larger product with a strong design system, which is exactly what drew me to this position.

  • Why should we hire you?

    BeginnerHR

    What the interviewer is evaluating

    Whether you understand the role and can match your strengths to its needs with evidence.

    Key points a strong answer covers

    • Role's needs. Show you understand what the role needs.
    • Matching strengths. Match two or three strengths to those needs.
    • Evidence. Back each with evidence.
    • Enthusiasm. Close with genuine enthusiasm.

    Suggested answer structure

    1. Name the two or three things the role needs most.
    2. Match each with your experience and evidence.
    3. Add what makes you different.
    4. Finish with genuine interest.

    Common mistakes

    • Generic claims like 'I'm hardworking' with no evidence.
    • Comparing yourself to other candidates you don't know.

    Likely follow-up questions

    • What would you do in your first 90 days?
    • What's one area where you'd need support?
    Example strong answer

    From the job description and our conversation, you need someone who can take ownership of the customer onboarding process, work with sales and product, and improve the numbers. I've done exactly that for three years: at my current company I redesigned onboarding for new accounts and cut the time to first value from 14 days to 6. I'm comfortable working across teams — I run a weekly session with sales and product on customer feedback — and I'm very data-driven, so I'd measure everything from day one. I'm also genuinely excited about your product, because it solves a problem I've seen customers struggle with.

  • Tell me about a time you disagreed with a teammate. How did you handle it?

    BeginnerBehavioural

    What the interviewer is evaluating

    Handling conflict constructively and keeping relationships.

    Key points a strong answer covers

    • Listened to their view. Show you listened to understand their view.
    • Used facts / common goal. Bring it back to facts or a shared goal.
    • Resolution & relationship. Resolve it and keep the relationship.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Making the other person the villain.
    • A story where you were simply right and they gave in.

    Likely follow-up questions

    • What if you couldn't reach agreement?
    • Have you ever been wrong in a disagreement?
    Example strong answer (a fictional story — use your own)

    On a website rebuild, a senior designer wanted an animated, image-heavy homepage, and I was worried it would hurt mobile load times and SEO. As the developer responsible for performance, I needed us to agree before the sprint started. I asked her to walk me through what she was trying to achieve — she wanted the brand to feel premium. I built two quick prototypes, one with her full design and one with lighter animations, and we tested both on a mid-range phone together. Hers took nearly six seconds to load. We agreed on a version that kept the key animation but lazy-loaded the rest. The page launched loading in under two seconds, and she later asked me to review designs earlier. I learned that testing together beats debating.

  • Tell me about a mistake you made and what you learned.

    BeginnerBehavioural

    What the interviewer is evaluating

    Honesty, accountability and learning.

    Key points a strong answer covers

    • Real mistake owned. Own a real mistake.
    • Fixed it. Show how you fixed it and who you told.
    • Changed behaviour. Show what you changed afterwards.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Choosing a fake mistake like 'I work too hard'.
    • Blaming others.

    Likely follow-up questions

    • How did your manager react?
    • How do you know you haven't repeated it?
    Example strong answer (a fictional story — use your own)

    In my first year as a marketing coordinator, I sent a promotional email to our whole list with the wrong discount code — I'd tested the email but not clicked the code itself. Within an hour customers were complaining that it didn't work. I told my manager immediately, set the wrong code to apply the discount too, and sent a short correction email with an apology. We lost very little revenue, and some customers replied thanking us for the quick fix. Since then I use a pre-send checklist that includes testing every link and code as a customer would, and I asked for a second person to check any campaign to more than 10,000 people.

  • Describe a situation where you worked under pressure or to a tight deadline.

    BeginnerBehavioural

    What the interviewer is evaluating

    Prioritisation, composure and delivery.

    Key points a strong answer covers

    • The pressure. Make the pressure concrete.
    • Prioritised. Show how you prioritised.
    • Communicated. Show how you kept people informed.
    • Delivered. Show the outcome.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Glorifying working all night as the solution.
    • No mention of prioritising.

    Likely follow-up questions

    • What would you do if it was clear you couldn't make the deadline?
    • How do you stop pressure affecting quality?
    Example strong answer (a fictional story — use your own)

    Two days before a client presentation, our analyst fell ill and I had to finish the market research report she'd been leading. I listed everything left and asked the account director which sections the client cared about most — pricing and competitor comparison. I focused on those, reused verified data from our previous report, and moved the appendix to a follow-up email. I sent a short update each evening so nobody was surprised. We delivered the core report on time, the client approved the next phase, and the appendix followed two days later. I learned to ask early what matters most rather than trying to do everything equally well.

  • What would you do if you realised you were going to miss a deadline?

    BeginnerSituational

    What the interviewer is evaluating

    Transparency and problem solving.

    Key points a strong answer covers

    • Tell people early. Flag it as soon as you know.
    • Assess the gap. Work out how far off you are.
    • Options. Offer options: reduced scope, help, a new date.
    • Prevent repeats. Learn why it happened.

    Suggested answer structure

    1. Clarify the situation and what's at stake.
    2. Say what you'd do first, and why.
    3. Explain who you'd involve and how you'd communicate.
    4. Describe how you'd check the outcome and prevent a repeat.

    Common mistakes

    • Waiting until the deadline to say anything.
    • Promising you'll just work all night.

    Likely follow-up questions

    • What if your manager is unavailable?
    • Has this happened to you?
    Example strong answer

    I'd tell the person depending on it as soon as I realised, not at the deadline. Before that conversation I'd work out how far off I am and why, so I could offer options: delivering the most important part on time and the rest a few days later, getting help from a colleague, or agreeing a new date. Then I'd let them decide what works best for them, and keep them updated. Afterwards I'd look at why it slipped — usually underestimating something — so I plan better next time.

Ready to answer them out loud?

Run a timed python developer mock interview, type or speak your answers, and get a score breakdown with what to improve.

Interview questions for related roles