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 in and not in operators
  • Use in and not in with different data types
  • Work with operator.contains(), the equivalent function to the in operator
  • Provide support for in and not 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,

 

 

 

To finish reading, please visit source site