Programming & syntax · reviewed in July 2026
Type hint
A type hint is an optional Python annotation that states the expected type of a variable, parameter, or return value — for example def add(a: int, b: int) -> int. Python doesn't enforce them at runtime, but tools like mypy or your editor use them to catch bugs before the code ever runs.
Frequently asked questions
Do type hints make Python statically typed?
No. Python is still dynamically typed at runtime; type hints are metadata that external tools (linters, editors, mypy) use for static analysis, but they don't change the program's behavior on their own.
What is Pydantic and how does it relate to type hints?
Pydantic is a library that DOES validate type hints at runtime: it defines data models with type annotations and automatically rejects values that don't match.
Do you have to annotate every variable?
No, they're optional throughout the language. They're used mostly on function signatures and public APIs, where they help readers and consumers of the code the most.