Python Interview Questions and Answers

Python interviews mix language trivia with real-world judgement. Freshers are asked about data structures and function arguments, mid-level candidates about decorators, generators and memory, and senior candidates about the GIL and how to choose between threads, processes and asyncio.

Usually asked in backend and full stack interviews, from intern / fresher to senior (5+ years).

Intern / Fresher

  1. Q1Intern / Fresher
    What is the difference between a list and a tuple in Python?

    A list is mutable and can be changed after creation, while a tuple is immutable; tuples are slightly faster, use less memory and can be used as dictionary keys when their items are hashable.

  2. Q2Intern / Fresher
    What is the difference between is and == in Python?

    == checks whether two objects have equal values, while is checks whether they are the exact same object in memory.

Junior (0-2 years)

  1. Q1Junior (0-2 years)
    What are *args and **kwargs in Python?

    *args collects extra positional arguments into a tuple and **kwargs collects extra keyword arguments into a dictionary, which lets a function accept a variable number of arguments.

  2. Q2Junior (0-2 years)
    Why should you not use a mutable default argument in Python?

    Default argument values are evaluated once when the function is defined, so a default list or dictionary is shared between every call that does not pass its own, causing data to leak between calls.

  3. Q3Junior (0-2 years)
    What is the difference between a shallow copy and a deep copy in Python?

    A shallow copy creates a new container but reuses the same nested objects, while a deep copy recursively copies everything so the new object is fully independent.

  4. Q4Junior (0-2 years)
    What is the difference between @staticmethod and @classmethod in Python?

    A classmethod receives the class as its first argument (cls) and can create or configure instances, while a staticmethod receives no automatic argument and is just a function placed inside the class namespace.

Mid-level (2-5 years)

  1. Q1Mid-level (2-5 years)
    What are decorators in Python and how do they work?

    A decorator is a function that takes another function and returns a modified version of it, letting you add behaviour such as logging, caching or access control without changing the original code.

  2. Q2Mid-level (2-5 years)
    What are generators and the yield keyword in Python?

    A generator is a function that uses yield to produce values one at a time and remembers its state between calls, so it can process large or infinite sequences without holding everything in memory.

  3. Q3Mid-level (2-5 years)
    How does Python manage memory and garbage collection?

    CPython frees objects mainly through reference counting, deleting an object as soon as nothing refers to it, and uses a cyclic garbage collector to clean up groups of objects that reference each other.

Senior (5+ years)

  1. Q1Senior (5+ years)
    What is the GIL in Python and how does it affect multithreading?

    The Global Interpreter Lock (GIL) in CPython lets only one thread execute Python bytecode at a time, so threads do not speed up CPU-bound code but still help with I/O-bound work.

  2. Q2Senior (5+ years)
    What is the difference between threading, multiprocessing and asyncio in Python?

    Threading runs concurrent threads that share memory and suit blocking I/O, multiprocessing runs separate processes to use multiple CPU cores for CPU-bound work, and asyncio runs many non-blocking tasks cooperatively on one thread for high-volume I/O.