Basic Type Annotations
Annotate variables, function parameters, and return types.
What Are Type Annotations?
Type annotations are hints that declare the expected type of variables, parameters, and return values. They are not enforced at runtime — they are read by type checkers like mypy.
def greet(name: str) -> str:
return f"Hello, {name}"
result: str = greet("Alice")
print(result)Variable Annotations
Annotate module-level, class-level, or local variables with a colon followed by the type.
count: int = 0
pi: float = 3.14159
name: str = "Python"
flag: bool = True
# Annotation without assignment (declaration only)
future_value: int