Python Type Hints
Multiple Choice Medium
Question
What does `def f(x: int) -> str:` declare?
Hint
Type hints are annotations, not runtime enforcement.
Explanation
Type hints declare that x should be an int and the function should return a str. They are annotations for documentation and static type checkers (like mypy) — Python does not enforce them at runtime. You can still pass wrong types without an error.
Related Resources
Related Lessons
- Type Hints
Type hint syntax.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.