Membership Operators in Python

These operators provide an easy way to check if a certain object is present in a sequence: string, list, tuple, set, and dictionary.

They are:

  • in: returns True if the object is present
  • not in: returns True if the object is not present

Let’s see a program that shows how each of them is used.

number_list = [1, 2, 4, 5, 6]

print( 1 in number_list)

print( 5 not in number_list)

print( 3 not in number_list)
True

False

True