"React Basics (2018)" was retired on March 31, 2024. You are now viewing the recommended replacement.
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 Object-Oriented Python!
You have completed Object-Oriented Python!
Preview
Being able to identify object classes and types is a really useful ability.
-
isinstance(<object>, <class>)- This function will tell you whether or not<object>is an instance of<class>. If it could be an instance of several classes, you can use a tuple of classes like so:isinstance(<object>, (<class1>, <class2>, <class3>)). -
issubclass(<class>, <class>)- This function will tell you whether or not one class is a descendent of another class. Just likeisinstance(), you can use a tuple of classes to compare against. -
type(<instance>)will give you the class for an instance, as willinstance.__class__. Neither of these is particularly useful.
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
useful functions for identifying what
kind of objects we're working with.
0:00
So, these functions aren't necessarily
something you're going to use every day or
0:03
even something you're gonna
wanna use all the time.
0:07
They are, however, really handy when
you need to act a certain way or
0:10
an object,
depending on what kind of object it is.
0:13
If Python is duck typed,
0:16
consider this to be how you separate
the mallards from the mandarins.
0:18
So I'm gonna hop into Python, and
0:21
I'm just gonna show what these do because
they're really fun and interactive.
0:23
The first is probably the one that
you're going to use the most often.
0:28
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