CAP/TP02/python/typecheck.py
2024-09-30 14:32:21 +02:00

16 lines
385 B
Python

# Typing annotations for variables:
# name: type
int_variable: int
float_variable: float
int_variable = 4 # Static typing error, but no runtime error
float_variable = 42.0 # OK
float_variable = int_variable # OK
# Typing annotations for functions (-> means "returns")
def int_to_string(i: int) -> str:
return str(i)
print(int_to_string(42)) # Both static and runtime error