A real use: hints on a shopping bill
Every function says what it takes and what it gives back. A reader (or a checker) knows prices are decimals and the cart maps item names to prices without opening the function bodies.
A type hint is a label that says what kind of value a variable, parameter or return value is meant to be. Python stores the label but never enforces it while the program runs; editors and checker programs read it to catch mistakes early.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write area(width: float, height: float) -> float and print area.__annotations__.
Write shout(text: str) -> str that returns the text in capitals, then call it with the number 5. What happens, and does the hint stop it?
Declare count: int without a value and show what happens when you print count.
Explain it without notes
Does Python enforce type hints? What reads them, then?
What is gradual typing and why does it matter for existing codebases?
What does Any do for a type checker, and why is it risky?
What does name: str with no value do?
What is the difference between Any and object as a hint?
Expected output
tea 20.00
milk 30.50
bread 45.00
total: 95.5
with 10% off: 85.95
{'prices': list[float], 'discount_percent': <class 'int'>, 'return': <class 'float'>}