Getting started with Python type hints


Python tip:

Use type hints to annotate expected types for variables, function parameters, and function returns.

https://testdriven.io/blog/python-type-checking/

An example👇

from typing import Collection


def daily_average(temperatures: Collection[float]) -> float:
    return sum(temperatures) / len(temperatures)


print(daily_average.__annotations__)
# => {'temperatures': typing.Collection[float], 'return': <class 'float'>}