Checking for Membership Using Python's "in" and "not in" Operators - Real Python
Briefly

This article explains Python's membership operators, 'in' and 'not in', which are used to verify if a value exists within a collection. These operators are very versatile, supporting various data types such as lists, tuples, ranges, and dictionaries. Additionally, the article mentions the operator.contains() function as an equivalent to the 'in' operator. It also highlights how developers can enable membership testing in custom classes by implementing specific methods like .__contains__(), .__iter__(), or .__getitem__().
Python's membership operators, 'in' and 'not in', allow quick checks for membership within collections, streamlining the process and enhancing code clarity.
There are several data types in Python, including lists, tuples, ranges, and dictionaries, that work seamlessly with the 'in' and 'not in' operators for checking membership.
Read at Realpython
[
|
]