Skip to main content

Python: Membership Operators

Membership Operators test for membership in a sequence, such as strings, lists, or tuples but in dictionary we can only test for presence of key, not the value.

Operator Description Syntax
in If a sequence with the specified value is present in the object. Returns True. a in b
not in If a sequence with the specified value is not present in the object. Returns True. a not in b

Example:

a = "ProgramsBuzz"
print("g" in a)
print("d" not in a)

Output:

True
True
Tags
Submitted by devanshi.srivastava on June 25, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.