Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Membership testing is a distinguishing feature of sets. Testing for membership means asking if an element is present in a set. Sets can have relationships with each other based on their mutual membership.
These operations return a boolean value.
Testing for Membership
x in set
True if set contains element.
x not in set
True if set does not contain element.
Testing for Equality
==
"equal to" - True if two sets are equal length and contain the exact same members
!=
"not equal to" - Opposite of "equal to"
Testing for Relationship
isdisjoint()
- True if two sets have a null intersection (ie. no members in common).
issubset()
/ <=
- True if another set contains this set.
issuperset()
/ >=
True if this set contains another set.
An empty set is both a disjointed set and a subset of all sets.
A set is both a subset and a superset of itself.
Extra Credit
The string
module has constants that are good for working with strings. Python has a lot of built-in modules that are very useful to know. You may be familiar with some already, like random
, time
, or statistics
. These modules are part of the Python Standard Library. Modules are vital to know about because it's code that other people wrote to handle common patterns and problems in programming. And you get these for free just by having Python installed on your computer! You can view an index of the built-in modules in the Python documentation
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
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