Ship It: Testing, Git & Sharing Your Apps / Make it solid
Lesson 4 of 10
Type hints
Type hints say what kind of values a function expects and returns. Editors use them to catch mistakes while you type.
Key points
- def add(a: int, b: int) -> int:
- list[str], dict[str, int]
- Python doesn't enforce them at runtime
def average(scores: list[float]) -> float:
return sum(scores) / len(scores)Your turn
Add type hints to every function in your to-do app.
Quiz · +10 XP
Does Python stop the program if a type hint is wrong?
Log in to save progress and earn XP.