Sometimes, we want to add type hint for a collection of a specified type with Python.
In this article, we’ll look at how to add type hint for a collection of a specified type with Python.
How to add type hint for a collection of a specified type with Python?
To add type hint for a collection of a specified type with Python, we can specify the type after the colon.
For instance, we write
def my_func(l: list[int]):
pass
to specify that the l
parameter in my_func
is a list of ints with list[int]
.
Conclusion
To add type hint for a collection of a specified type with Python, we can specify the type after the colon.