· intermediate
Type Hints in Python
Say what a function expects and returns, and let a checker find the mistakes before the program runs. Annotations, the shapes that describe real code, and how to add them to a codebase gradually.
Written in house, from the work rather than from a syllabus. Every example is one we would use ourselves, and every exercise is checked against the same engine that grades your answer.
What you’ll learn
- Annotate arguments and return values, and know what Python does and does not enforce
- Describe containers precisely with list, dict and tuple annotations
- Handle a value that may be absent with X | None, and narrow it before use
- Constrain a string to a fixed set of values with Literal
- Describe what an object can do rather than what it inherits, using Protocol
- Adopt typing gradually, and know where annotations pay for themselves
Before you start
- · Comfortable writing functions and classes
- · Familiar with lists, dictionaries and exceptions