Skip to main content

Python Membership Operators

Membership Operators

Membership operators are used to test whether a value or variable is in a sequence.

OperatorDescriptionExample
inTrue if value/variable is found in the sequence2 in x
not inTrue if value/variable is not found in the sequence2 not in x

Examples

my_list = [1,2,3,4,5,6,7,8,9,10]
a = 5
b = 50

print(a in my_list) # True
print(a not in my_list) # False

print(b in my_list) # False
print(b not in my_list) # True

print(1 in my_list) # True
print(1 not in my_list) # False
print(20 in my_list) # False
print(20 not in my_list)# True