Career Scan

Interview practice with an AI panel

Interview questions

Python developer interview questions

Python interviews test whether you write idiomatic, readable code and understand what happens underneath: how objects, references and the interpreter behave. For backend roles they add web frameworks, databases, testing and performance.

The questions below go from basic to advanced. Use the notes under each one to check your answer covers the points interviewers listen for.

Looking for questions for freshers and graduates? Python interview questions for freshers

What interviewers assess

Basic questions

  1. What is the difference between a list and a tuple?

    What a good answer covers: Lists are mutable, tuples are immutable; tuples can be dictionary keys if their contents are hashable; tuples signal fixed structure. Mention that immutability is about the container, not the objects inside it.

  2. Why is using a mutable default argument like def f(x=[]) a problem?

    What a good answer covers: The default is evaluated once when the function is defined, so the same list is shared between calls. The fix is a None default and creating the list inside the function.

  3. Explain list comprehensions and generator expressions. When would you prefer a generator?

    What a good answer covers: Comprehensions build the whole list in memory; generators produce items lazily. Prefer generators for large or streaming data, or when you only iterate once.

  4. How do *args and **kwargs work?

    What a good answer covers: Collect extra positional arguments into a tuple and keyword arguments into a dict; also used to unpack when calling. A good answer mentions forwarding arguments in decorators or wrappers.

  5. How are dictionaries implemented, and what makes a key valid?

    What a good answer covers: A hash table; keys must be hashable (immutable or with stable __hash__ and __eq__). Since Python 3.7, dicts keep insertion order.

Intermediate questions

  1. What is a decorator? Write one that times a function.

    What a good answer covers: A function that takes a function and returns a wrapped one; use functools.wraps to keep the name and docstring. Explaining the closure clearly matters more than the syntax.

  2. What is the difference between a shallow copy and a deep copy?

    What a good answer covers: A shallow copy duplicates the outer container but shares nested objects; a deep copy duplicates everything recursively. Give an example where a shallow copy causes a bug.

  3. How would you structure and test a FastAPI or Flask service?

    What a good answer covers: Separate routes, business logic and data access; dependency injection for the database; pytest with fixtures, a test client and a test database. Mention testing error paths, not only the happy path.

  4. Explain context managers and the with statement.

    What a good answer covers: __enter__ and __exit__ guarantee clean-up such as closing files or releasing locks even when exceptions happen. contextlib.contextmanager is a shortcut for writing your own.

  5. How do you manage dependencies and environments in a Python project?

    What a good answer covers: Virtual environments, pinned versions in a lock or requirements file, and tools such as pip-tools, Poetry or uv. Explain why reproducible builds matter in production.

Advanced questions

  1. What is the GIL and how does it affect concurrency?

    What a good answer covers: In CPython the global interpreter lock lets only one thread run Python bytecode at a time, so threads help with I/O-bound work but not CPU-bound work, which needs multiprocessing or native extensions. Mention the free-threaded builds now being introduced.

  2. When would you use asyncio instead of threads?

    What a good answer covers: Many concurrent I/O operations (network calls, websockets) with low overhead per task. Caveats: one blocking call stalls the event loop, and every library in the path must be async-aware.

  3. A Python endpoint is slow. How do you find out why?

    What a good answer covers: Measure first: logs and timings, then a profiler such as cProfile or py-spy, and look at database queries. Fix the biggest cost (often N+1 queries or repeated work), then measure again.

  4. How does Python manage memory?

    What a good answer covers: Reference counting frees most objects immediately; a cyclic garbage collector handles reference cycles. Mention memory leaks through global caches and lingering references.

  5. Explain metaclasses or descriptors and a real use for one.

    What a good answer covers: Descriptors power properties and ORM fields; metaclasses customise class creation (such as model registration in Django). A strong answer says that most code shouldn't need them.

Common mistakes

How to prepare

Reading questions only goes so far: the real test is answering them aloud, under follow-up questions. Career Scan builds a mock interview from your own resume and the job, then shows exactly which answers need work.

Frequently asked questions

Do Python interviews focus on data structures and algorithms?

Most include at least one coding round. Python's built-in structures (dict, set, deque, heapq) make many problems shorter, so know them well.

Which framework should I prepare: Django, Flask or FastAPI?

Prepare the one the job description names and the one on your resume. The concepts (routing, validation, ORM, testing) carry over between them.

Is Python 2 still asked about?

Rarely. Prepare for Python 3, including type hints, f-strings and dataclasses.

Related interview questions