0Pricing
Python Academy · Lesson

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

All lessons in this course

  1. Basic Type Annotations
  2. Complex Types: List, Dict, Optional, Union
  3. TypeVar, Generic Classes, and Protocol
  4. Running mypy and Fixing Type Errors
← Back to Python Academy