Membership operators test whether a value is in a sequence or collection.
| Operator | Meaning | Example |
|---|---|---|
in |
value is present | "a" in "cat" |
not in |
value is absent | 4 not in [1, 2, 3] |
text = "Hello world"
data = {1: "a", 2: "b"}
print("H" in text) # True
print("hello" in text) # False (case-sensitive)
print(1 in data) # True (checks keys)
print("a" in data) # FalseFor dictionaries, in checks keys, not values.