Categories
Python Answers

How to add type hint for a collection of a specified type with Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *