👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I have a function in python that can either return a bool
or a list
. Is there a way to specify the return types using type hints.
For example, Is this the correct way to do it?
def foo(id) -> list or bool:
...
Python typing multiple types

👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from How to specify multiple return types using type-hints, check other code Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano How to specify multiple return types using type-hints
- Deutsch How to specify multiple return types using type-hints
- Français How to specify multiple return types using type-hints
- Español How to specify multiple return types using type-hints
- Türk How to specify multiple return types using type-hints
- Русский How to specify multiple return types using type-hints
- Português How to specify multiple return types using type-hints
- Polski How to specify multiple return types using type-hints
- Nederlandse How to specify multiple return types using type-hints
- 中文 How to specify multiple return types using type-hints
- 한국어 How to specify multiple return types using type-hints
- 日本語 How to specify multiple return types using type-hints
- हिन्दी How to specify multiple return types using type-hints
San Francisco | 2023-02-07
Thanks for explaining! I was stuck with How to specify multiple return types using type-hints for some hours, finally got it done 🤗. I am just not quite sure it is the best method
Munchen | 2023-02-07
I was preparing for my coding interview, thanks for clarifying this - How to specify multiple return types using type-hints in Python is not the simplest one. Will use it in my bachelor thesis
New York | 2023-02-07
Thanks for explaining! I was stuck with How to specify multiple return types using type-hints for some hours, finally got it done 🤗. Will use it in my bachelor thesis