Python’s “in” and “not in” Operators: Check for Membership
![](https://www.deeplearningdaily.com/wp-content/uploads/2022/12/pythons-in-and-not-in-operators-check-for-membership_63a0a3b238163-375x210.jpeg)
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
in
andnot in
operators - Use
in
andnot in
with different data types - Work with
operator.contains()
, the equivalent function to thein
operator - Provide support for
in
andnot in
in 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,