in: Returns True if the value is found in the sequence.
Syntax: value in sequence
not in: Returns True if the value is not found in the sequence.
Syntax: value not in sequence
Python program that demonstrates the use of Membership operators:
# Define a list and a string fruits = ['apple', 'banana', 'cherry'] text = 'Hello, World!' # Using the 'in' operator print('apple' in fruits) # True print('grape' in fruits) # False print('World' in text) # True print('world' in text) # False # Using the 'not in' operator print('apple' not in fruits) # False print('grape' not in fruits) # True print('World' not in text) # False print('world' not in text) # True
Output
True False True False False True False True