Membership Operator (in)

noun

say it: “MEM-ber-ship OP-uh-ray-ter” /ˈmɛmbərˌʃɪp ˈɑpəˌreɪtɚ/ or “in” /ɪn/

The word in used as a question: it checks whether a value is inside a list, string, dictionary or other collection and answers True or False.

What does the in operator do?

The in operator checks whether a value is inside a list, string, dictionary or other collection, and answers True or False.

allergies = ["peanuts", "shellfish"]
print("peanuts" in allergies)  # True
print("gluten" in allergies)   # False

In a sentence

  • “The membership operator checks whether "peanuts" is in the customer's list of allergies.”
  • “Before adding a song, the playlist code uses the membership operator to see if it's already there.”

Level: Apprentice · More Python terms at this level

Updated