Skip to main content
Loading page…
Python Mastery
Chapter 18
Lesson 1 of 3
Type Hints Basics
Contents
Notes
Tutor
Concept
Why Type Hints Exist
Loading activity…
Previous
1 / 8
Continue
Contents
Notes
Discussion
Tutor
25 min
8 activities
0 of 8 done
In this lesson
1
Why Type Hints Exist
2
Collection Types: list, dict, tuple, set
3
Optional and Union: Handling Absence and Multiple Types
4
Quick Check: Optional vs Union
5
Type Aliases: Naming Complex Types
6
Pitfall: Type Hints Do Not Raise Errors at Runtime
7
Practice: Annotate a Student Grade Book
8
Pro Tip: Annotations Are Accessible at Runtime via __annotations__
Objectives
Annotate variables, function parameters, and return types with built-in and collection types
Use Optional, Union, and the | shorthand to express nullable and multi-type values
Define and use type aliases to make complex annotations readable
Explain that type hints are not enforced at runtime and describe their actual purpose
Further reading
typing - Support for type hints
typing specification
Chapter 18 · Type Hints & Static Typing
Type Hints Basics
Static Typing with mypy and pyright
Generics, Protocols & Advanced Typing
Previous: Context Managers (with)
Next: Static Typing with mypy and pyright