Membership Operators in Python

In all programming languages you will not find membership operators in Python. Membership operators are used to test if a sequence is presented in an object. There are two membership operators in Python.

Now, let’s see the membership operators in Python:

Operator Description Example
in Returns True if a sequence with the specified value is present in the object x in y
not in Returns True if a sequence with the specified value is not present in the object x not in y

Python example with membership operators:

m = ["Minhajur", "Rahman", "Khan"]
r = "Rahman"
if r in m:
    print("exist the object")
else:
    print("not exist the object")
Output:
exist the object

In this tutorial, I have shown membership operators in Python. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.

Add a Comment