<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>
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.
Java usually use Static typing β The checks are performed without running the program.
//The first line declares that the variable
String x;
x = 'Hello'
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.
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.
# The variable pi has been annotated with the float type hint.
pi: float = 3.142