type hint

A note in a function heading or variable declaration saying what type a value should be, such as def total(prices: list[float]) -> float:.

In more detail

Python ignores hints while the program runs: a wrong type still runs, or fails exactly as it would without them. Tools such as mypy and editors read them to catch mistakes early and to offer better completions. They pay off most on functions other people call.

Example

def greet(name: str) -> str:
    return "Hello, " + name

Related terms

Taught in

References