Skip to content
Sharp

Type Hints · interview question

A bug appears around optional and collections. What is the strongest first debugging move?

Multiple choiceEasychapter-10-curatedpremiumtype-hintsoptional-and-collections
python
from typing import Optional

def normalize_coupon(code: Optional[str]) -> str:
    return code or ""
Choose one answer
Answer and explanation

Correct answer

D. 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. If None and collection contents are left implicit, edge cases spread across many call sites.

Test yourself on Type Hints

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

Start free test
All Type Hints questions →