Documentation: Annotations

Learn how annotations are used for type hinting in Python.

We'll cover the following

The basic idea of annotations is that they hint to the readers of the code what to expect as values of arguments in functions. The use of the word hint is not casual; annotations enable type hinting.

Annotations let us specify the expected type of some variables that have been defined. It is actually not only about the types, but any kind of metadata that can help us get a better idea of what that variable actually represents.

Consider this example:

Get hands-on with 1200+ tech skills courses.