built-in generic types
Container types in type hints written with their item types in square brackets, such as list[str] or dict[str, int].
In more detail
Since Python 3.9 the built-in names list, dict, tuple and set can be subscripted this way directly in hints. They describe what the container holds; nothing is checked at run time.
Related terms
- 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:.
- list — An ordered, changeable collection of values written in square brackets, such as [3, 1, 4].
- dictionary — A Python collection that stores values under keys, written in curly brackets, such as {"tea": 250}.
Taught in
- Type Hints — Hands-on Python: Complete Video Course & Book