SOARDO
Software Engineer (SDE)pythonintermediate3 interactive MCQs in app

Type Annotations: Optional, Union, List & Dict

type narrowing for Optional / T | Nonestatic compile/CI checking vs zero runtime enforcementstructural subtyping with Protocol

Type hints (`str | None`, `list[int]`, `dict[str, float]`, `TypedDict`, `Protocol`) document function contracts explicitly so static checkers (`mypy` / `pyright`) catch `None`-dereference bugs and wrong dict shapes BEFORE runtime! Important: Python **does NOT enforce type annotations at runtime** automatically—hints are metadata only unless paired with runtime validators like Pydantic!

`email: str | None = users.get(uid)` makes `email.lower()` fail `mypy`, whereas `if email is not None: return email.lower()` narrows the type safely!
assuming `def pay(cents: int)` rejects `"100"` at runtime without validation, or omitting `if user is not None:` narrowing on `User | None` returns.
Python Type Checking — Real Pythonread ↗Type Annotations: Optional, Union, List & Dict — Applied Practicepractice ↗Exercism Python Track (Interactive)practice ↗

Practice Type Annotations: Optional, Union, List & Dict with 3 graded MCQs & written feedback.

Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.

Test yourself free on SOARDO →View full Software Engineer roadmap

More Software Engineer Study Guides