Skip to content
Sharp

Python Internals · interview question

A bug appears around mutability traps. What is the strongest first debugging move?

Multiple choiceMediumchapter-19-curatedpremiumpython-internalsmutability-traps
python
def add_flag(flags: list[str] | None = None) -> list[str]:
    flags = [] if flags is None else flags
    flags.append("seen")
    return flags
Choose one answer
Answer and explanation

Correct answer

A. Trace one concrete example, inspect the state transitions, and compare them to the intended rule before rewriting anything.

Why

That approach is reliable because it creates evidence. Mutable defaults and hidden shared containers create bugs that feel spooky until you know the model.

Test yourself on Python Internals

A free test with instant, explained results. No account needed.

Start free test
All Python Internals questions →