Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Using Type Hints for Multiple Return Types in Python (Summary)

Although type hinting is optional, it’s a useful concept to make your code more readable, user-friendly, and easier to debug. Type hints signal to other developers the desired inputs and return types of your functions, facilitating collaboration.

In this video course, you focused on implementing type hints for more complex scenarios and learned best practices for using and maintaing them.

In this video course, you’ve learned how to use:

  • The pipe operator (|) or the Union type to specify alternative types of one piece of data returned from a function
  • Tuples to specify distinct types of multiple pieces of data
  • The Callable type for annotating callback functions
  • The Generator, Iterator, and Iterable types for annotating generators
  • Type aliases for type hints to help simplify complex type hints that you reference in multiple places in your code
  • Mypy, a third-party tool for type checking

Now you’re ready to use type hints in a variety of scenarios. How do you use type hints in your code? Share your use cases in the comments below.

Download

Course Slides (.pdf)

7.0 MB
Download

Sample Code (.zip)

5.1 KB

Become a Member to join the conversation.