20 questions · Updated June 2026

Top Python Interview Questions and Answers (2026)

Python interviewers care less about syntax trivia and more about how you reason about memory, concurrency and idiomatic design. These questions reflect that balance.

Book a free demo
  1. Q01.What's the difference between a list and a tuple?

    Lists are mutable and use square brackets. Tuples are immutable and use parentheses. Tuples are hashable and slightly faster, making them good dictionary keys.

  2. Q02.What is the GIL?

    The Global Interpreter Lock is a mutex that protects access to Python objects, allowing only one thread to execute Python bytecode at a time. CPU-bound multithreading is therefore limited; use multiprocessing or async I/O for parallelism.

  3. Q03.Explain shallow vs deep copy.

    `copy.copy()` makes a top-level duplicate sharing nested references. `copy.deepcopy()` recursively duplicates every nested object.

  4. Q04.What are decorators?

    Functions that wrap other functions to add behaviour without changing the wrapped function's body. The `@decorator` syntax applies one.

  5. Q05.What is a generator?

    A function that uses `yield` to produce values lazily. Generators are memory-efficient because they don't materialise the whole sequence.

  6. Q06.Difference between *args and **kwargs?

    `*args` captures positional arguments as a tuple. `**kwargs` captures keyword arguments as a dict.

  7. Q07.What is the difference between is and ==?

    `is` compares identity (same object in memory). `==` compares equality (logical value).

  8. Q08.What does PEP 8 cover?

    Python's style guide — indentation, line length, naming conventions, import ordering. Tools like `ruff` and `black` enforce it automatically.

  9. Q09.Explain list comprehensions.

    A concise syntax for building lists: `[expr for item in iterable if condition]`. Generally faster and more readable than explicit loops.

  10. Q10.What are __init__ and __new__?

    `__new__` creates the instance; `__init__` initialises it. You'll rarely override `__new__` outside of metaclass or singleton tricks.

  11. Q11.What is duck typing?

    Python checks behaviour, not type. If an object has the expected methods, it works — regardless of its class.

  12. Q12.How does Python manage memory?

    Reference counting plus a cyclic garbage collector. When an object's reference count drops to zero, memory is freed immediately.

  13. Q13.Difference between @staticmethod and @classmethod?

    `@staticmethod` ignores the class entirely. `@classmethod` receives the class as the first argument, useful for alternate constructors.

  14. Q14.What are context managers?

    Objects supporting the `with` statement that guarantee setup/teardown. Implemented via `__enter__` / `__exit__` or `contextlib.contextmanager`.

  15. Q15.What's the difference between sync and async functions?

    Sync functions run sequentially. Async functions return coroutines that yield control on `await`, enabling concurrent I/O without threads.

  16. Q16.What does the `with open(...)` pattern give you?

    Automatic file closing even if an exception is raised. Equivalent to `try/finally` with `f.close()`.

  17. Q17.Difference between deepcopy and pickle?

    Deepcopy clones objects in memory. Pickle serializes them to bytes for storage or transport. Pickle has security risks if loading untrusted data.

  18. Q18.What is the difference between yield and return?

    `return` exits a function with a value. `yield` produces a value and suspends the function, resuming on the next iteration.

  19. Q19.How do you handle dependencies in a Python project?

    Use a virtual environment per project, pin versions in `requirements.txt` or `pyproject.toml`, and prefer `pip-tools` or `uv` for reproducible installs.

  20. Q20.What is the difference between Flask and FastAPI?

    Flask is synchronous and minimal. FastAPI is async-first, validates with Pydantic and auto-generates OpenAPI docs — preferred for new APIs in 2026.

Interview prep support

Get 1:1 prep on Python

Our mentors will reach out with a personalised prep plan, mock interview slots and target-company question banks.