Python (Django / FastAPI) interview questions

Mutability traps, list vs tuple, comprehensions, decorators, generators, the GIL, virtual environments and web framework basics.

Readiness: 0 of 26 nailed

How to use this page: 1. Read a question2. Type your answer3. Check with AI4. Open the model answer5. Timed drill when you’re 70% ready

Gotchas

JuniorPredict the output

What does this print?

def add_item(item, items=[]):
    items.append(item)
    return items

print(add_item('a'))
print(add_item('b'))
JuniorPredict the output

What does this print?

original = [[1, 2], [3, 4]]
copy = list(original)
copy[0][1] = 99
print(original)
JuniorPredict the output

What happens here?

count = 0
def increment():
    count += 1
increment()
Mid-levelPredict the output

What does this print in CPython?

a = 256; b = 256
print(a is b)
x = int('1000'); y = int('1000')
print(x is y)

Basics

FoundationConcept

List vs tuple vs set vs dict?

FoundationConcept

What is the difference between is and ==?

FoundationWrite it by hand

Get the squares of even numbers from 1 to 10, then a dict of word → length.

FoundationConcept

What is the difference between d['key'], d.get('key') and defaultdict?

JuniorWrite it by hand

Sort a list of dicts by age descending, then name ascending.

Functions

Mid-levelWrite it by hand

Write a decorator that measures how long a function takes.

FoundationConcept

What are *args and **kwargs?

JuniorConcept

What is a generator, and when would you use one?

Concurrency

SeniorConcept

What is the GIL? Threads vs processes vs asyncio?

Mid-levelConcept

How does asyncio work, and what mistake blocks it?

Tooling

FoundationConcept

Why use a virtual environment?

Django

Mid-levelIt’s broken: why?

A Django list view is slow and makes hundreds of queries. How do you fix it?

JuniorConcept

Explain Django’s architecture (MVT) and the request flow.

Mid-levelConcept

What are Django signals, and why can they be a problem?

JuniorConcept

What are serializers in Django REST Framework?

FastAPI

Mid-levelConcept

Why would you choose FastAPI, and what is Pydantic’s role?

Language

JuniorWrite it by hand

What is a context manager? Write one.

JuniorConcept

How do you handle exceptions properly in Python?

JuniorConcept

Do type hints change how Python runs?

OOP

Mid-levelConcept

What are dunder (magic) methods? Give examples.

JuniorWrite it by hand

What does @dataclass give you?

Performance

Mid-levelReal-world scenario

Process a 20GB CSV file in Python with 4GB of RAM.

Also prepare