Type annotations#

Python supports type annotations in many positions. Here’s an example:

The type annotations above indicate that n is supposed to be an int and that factorial(n) will return an int.

Python does not actually enforce types in any way. If we called factorial('hi'), the code will run and we’ll get an error (where?). Tools like mypy help you find type errors. There’s been a lot written about types, but http://veekaybee.github.io/2019/07/08/python-type-hints/ is a good place to start.