Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Python Type Hinting!
You have completed Python Type Hinting!
Preview
Sometimes you can't specify your types just with the built-in types. In that case, you can us `Optional`, `Union`, and `List` from the `typing` module to specify custom type combinations.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
well, types that we can use when
creating hints for our code.
0:00
Let's look at something
a bit more complex.
0:01
I've been working on some classes
that all relate to recipes.
0:03
There's an ingredient class that's
already typed it just uses strings but
0:06
the ones in this model
are a bit more complicated.
0:10
For instance the recipe ingredient
class can when instantiated receive
0:13
either an ingredient or
a string to turn into an ingredient.
0:17
Maybe not the best design but
that's what I have to work with.
0:22
In the typing module there
are several types defined for
0:25
these more complex situations but
0:28
there are three of them that you'll find
yourself using more often than the others.
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up