Python’s “in” and “not in” Operators: Check for Membership
Python’s in and not in operators allow you to quickly determine if a given value is or isn’t part of a collection of values. This type of check is common in programming, and it’s generally known as a membership test in Python. Therefore, these operators are known as membership operators.
In this tutorial, you’ll learn how to:
- Perform membership tests using the
inandnot inoperators - Use
inandnot inwith different data types - Work with
operator.contains(), the equivalent function to theinoperator - Provide support for
inandnot inin your own classes
To get the most out of this tutorial, you’ll need basic knowledge of Python, including built-in data types, such as lists,