capypad
0 day streak
python / beginner
Snippet

Checking for Items with 'in'

The 'in' operator is a highly readable way to check if a specific value exists inside a sequence like a list or a string.

snippet.py
python
1
2
3
guest_list = ["Alice", "Bob", "Charlie"]
if "Alice" in guest_list:
print("Welcome!")
Breakdown
1
if "Alice" in guest_list:
Evaluates to True if the string is found anywhere in the list.
2
print("Welcome!")
Executes only if the membership check returned True.