Type Hints Purpose
Question
What are Python type hints for?
Hint
Type hints are optional and not enforced at runtime.
Explanation
Type hints (x: int = 5, def f(x: str) -> int:) are optional annotations that document expected types and enable static type checking with tools like mypy. They do not affect runtime behavior — Python does not enforce them. They improve code readability, enable IDE autocompletion, and catch type errors before running. They are increasingly common in modern Python codebases.
Related Resources
Related Lessons
- Type Hints
Learn Python type hints.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.