Type Hints
Type Hints — Type hints (introduced in Python 3.5) allow you to specify the expected types of function parameters and return values. Type hints improve code readability and enable static type checking with tools like `mypy` and `pyright`. They are optional at runtime — Python does not enforce them. The `typing` module provides `List`, `Dict`, `Optional`, `Union`, `Callable`, `Protocol` and more. Python 3.10+ allows simpler syntax like `str | None` instead of `Optional[str]`. This term relates to the Typing Module category of the reference. Related terms: Decorator, Generator, Context Manager, GIL (Global Interpreter Lock), Duck Typing, List Comprehension. Understanding type hints makes the rest of the Python documentation noticeably easier to follow, because the concept recurs across function references, guides, snippets, and error messages you will meet in real projects. Look up more definitions in the Python glossary, or put the concept into practice with an example from the Python playground.