👻 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
Abu Dhabi | 2023-01-28
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. I just hope that will not emerge anymore
Prague | 2023-01-28
Simply put and clear. Thank you for sharing. How to specify multiple return types using type-hints and other issues with http Python module was always my weak point 😁. Will get back tomorrow with feedback
Tallinn | 2023-01-28
Thanks for explaining! I was stuck with How to specify multiple return types using type-hints for some hours, finally got it done 🤗. Checked yesterday, it works!