📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Python from Zero Type Hints

Type Hints

5 min read
Type hints annotate functions: def greet(name: str) -> str. They do not enforce types at runtime but help IDEs catch errors early. Use mypy to run static type checking across your whole project.

Type Hints

from typing import Optional, List, Dict

def greet(name: str, times: int = 1) -> str:
    return (f"Hello, {name}! " * times).strip()

def process(users: List[Dict[str, int]]) -> Optional[str]:
    if not users:
        return None
    return users[0].get("name")

# Run type checking
# pip install mypy
# mypy script.py