<aside> πŸ‘¨πŸΌβ€πŸ’»

Typing systems formalizes which categories of objects it can work with and how those categories are treated.

</aside>

Support my work buying me a coffee β˜•

MartΓ­ Grau is R&D and IA engineer


<aside> πŸ’‘ You can also follow this guide or go to the oficial documentation: Typing documentation, Pydantic documentation

</aside>

Dynamic Typing

Python is a dynamically typed language β†’ This means that the Python interpreter does type checking only as code runs, and that the type of a variable is allowed to change over its lifetime.

Static Typing

Java usually use Static typing β†’ The checks are performed without running the program.

//The first line declares that the variable
String x;
x = 'Hello'

Duck Typing

Concept related to dynamic typing. Using duck typing you do not check types at all. Instead you check for the presence of a given method or attribute.

Typing

Module that provides runtime support for type hints.

To add information about types to the function, you simply annotate its arguments and return value as follows:

def greeting(name: str) -> str:
    return 'Hello ' + name
# str syntax says that the text argument should be of type str.
# the -> str notation specifies that greeting() will return a string.

Variable Annotations

# The variable pi has been annotated with the float type hint.
pi: float = 3.142

Types defined by Typing module