in — Easy Examples
Membership test operator; also used in for loops to iterate over items
Membership testing
Using 'in' to check if a value exists in a collection.
python
# in with lists fruits = ["apple", "banana", "cherry"] print("banana" in fruits) print("grape" in fruits) # in with strings text = "Hello, World!" print("World" in text) print("xyz" in text) # in with dictionaries (checks keys) ages = {"Alice": 30, "Bob": 25} print("Alice" in ages) print(30 in ages) # checks keys, not values
Expected Output
True False True False True False
'in' tests membership. For lists it checks values, for strings it checks substrings, for dicts it checks keys.
Want to try these examples interactively?
Open Easy Playground