🧭Type Annotation
Also known as Type Hint, Type Hints, Type Declaration
A note that says what kind of value a name holds, like count: number.
Think of it like
Think of it like a label on a jar. It says sugar, so nobody fills it with salt.
Example
Jack marks area to take two whole numbers and give one back. When he passes it a word by mistake, his editor shows a red line.
Why it matters
Annotations turn guesses into checked facts. Editors also use them to suggest the right names as you type.
Definition
Example code
python
def area(width: int, height: int) -> int:
return width * height
print(area(3, 4)) # 12Common mistake
Key takeaways
- 1A label on a name. Says what kind it holds.
- 2Read by checkers. They warn on a mismatch.
- 3Read by people. Shows what a function wants.