Membership Operator

Last updated: Apr 12, 2026

Membership Operators

Python membership operators are used to check for membership of objects in sequence, such as string, list, tuple. It checks whether the given value or variable is present in a given sequence. If present, it will return True else False. In Python, there are two membership operators.

  1. in : It returns a result as True if it finds a given object in the sequence. Otherwise, it returns False.

Example:

My_list = [11, 15, 21, 29, 50, 70]
number = 15
 
if number in My_list:
    print("number is present")
else:
    print("number is not present")

Output:

number is present
  1. not in : It returns True if the object is not present in a given sequence. Otherwise, it returns False.

Example:

my_tuple = (11, 15, 21, 29, 50, 70)
number = 35
 
if number not in my_tuple:
    print("number is not present")
else:
    print("number is present")

Output:

number is not present