Returning Data of Alternate Types in Python

preview_player
Показать описание
This is a preview of the video course, "Using Type Hints for Multiple Return Types in Python." With type hints in Python, you let other developers know the expected data types for variables, function arguments, and return values. As you write code for applications that require greater flexibility, you may need to specify multiple return types to make your code more robust and adaptable to different situations.

This is a portion of the complete course, which you can find here:

The rest of the course covers:
- How to Annotate Callable Objects
- How to Annotate Return Values
- Improve Readability With Aliases
- How to Leverage Tools for Static Type Checking
Рекомендации по теме
Комментарии
Автор

Is it not better to simply raise an exception if returning none? That way you always know what type being returned

alexandarjelenic
Автор

Option[str] is better, than Union[str, None]

yawneed