Locked lesson.
About this lesson
We'll look at the membership operators "In", and "Not In".
Exercise files
Download this lesson’s related exercise files.
Membership Operators.docx59 KB Membership Operators - Solution.docx
59.1 KB
Quick reference
Membership Operators
It's easy to test whether an item exists inside a given list, tuple, dictionary, or variable.
When to use
Use membership operators whenever you want to see if an item exists in a list, tuple, dictionary, or variable.
Instructions
The two membership operators are "In" and "Not In":
"john" in my_list #returns true if exists, false if not
"john" not in my_list #returns true if not exists, false if not
Hints & tips
- In and Not In test for membership
Lesson notes are only available for subscribers.