Python Membership Operators [in and not in] — A Complete Guide

Overview: Membership operators in Python are used to check if a value exists within a sequence or container. This includes lists, strings, tuples, sets, or dictionaries. They are particularly useful for loops, conditional statements, data validation, keyword searches, and presence checks.

1. What Are Membership Operators in Python?

Overview: TMembership operators are used to test if an element is a member of a given sequence. Python provides only two membership operators — in and not in.


fruits = ['apple', 'banana', 'cherry']

# Check if 'banana' exists
print('banana' in fruits)  # True

# Check if 'mango' does not exist
print('mango' not in fruits)  # True


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top