While Python is a dynamically typed language, there is a way to annotate types for clarity purposes. These are the built-in types:
int
float
bool
str
bytes
Complex types are available from the typing module:
List
Set
Dict
Tuple
Optional
etc.
Here is how you would define a function with type annotations:
def func1(x: int, y: str) -> bool:
return False
Generic type annotations are annotations that take another type as a parameter, allowing you to specify complex logic:
List[int]
Optional[List[int]]
Tuple[bool]
etc.
Note that these are only used for warnings and static type checking. You will not be guaranteed these types at runtime.