🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Python Intermediate

What is Type Hints?

Optional annotations that indicate the expected types of variables, function parameters, and return values.

Type hints (PEP 484) add optional type information to Python code: def greet(name: str) -> str. They do not enforce types at runtime but enable static analysis tools like mypy, IDE autocompletion, and better documentation.

Common types include int, str, List[int], Dict[str, Any], Optional[str], Union[int, str], and Tuple[str, ...]. The typing module provides advanced type constructs.