Top 25 Python Interview Questions (2026 Edition)

1. What is the difference between list and tuple?

Lists are mutable, meaning you can modify their contents after creation. Tuples are immutable.

my_list = [1, 2, 3]
my_list[0] = 99  # Allowed

my_tuple = (1, 2, 3)
# my_tuple[0] = 99  # Raises TypeError

Key Takeaway: Under the hood, tuples are slightly faster and consume less memory than lists because they are allocated in a single, static block of memory.

2. Explain decorators in Python

Decorators allow you to wrap another function to extend its behavior without permanently modifying it.

def log_decorator(func):
    def wrapper(*args, **kwargs):
        print(f"Calling function: {func.__name__}")
        result = func(*args, **kwargs)
        print(f"Function {func.__name__} completed.")
        return result
    return wrapper

@log_decorator
def greet(name):
    return f"Hello, {name}!"

3. How does Python manage memory?

Python utilizes automatic memory management consisting of two primary mechanisms: 1. Reference Counting: Every object tracks how many references point to it. Once this count drops to zero, the object is immediately deallocated. 2. Garbage Collection (GC): To handle cyclic references (e.g., Object A references Object B, which references Object A), Python's cyclic garbage collector runs periodically to detect and clean up isolated cyclic graphs.

Related Articles