Type hint in Python
Type hinting is not mandatory, but it can make your code easier to understand and debug by
Improved readability Better IDE support: IDEs and linters can use type hints to check your code for potential errors before runtime. While type hints can be simple classes like float or str , they can also be more complex. The typing module provides a vocabulary of more advanced type hints.
Basics 1 2 3 4 5 6 7 8 9 10 11 12 # This is how you declare the type of a variable age: int = 1 # You don't need to initialize a variable to annotate it a: int # Ok (no value at runtime until assigned) # Doing so can be useful in conditional branches child: bool if age < 18: child = True else: child = False 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 x: int = 1 x: float = 1.