You need identity operator to compare the strings. Similarly, you need membership operators to check if a value is present in another list /or not.
These two are special operators in Python. These operators look like English words. Here are the differences and how to use them.
IN THIS PAGE
Identity Operator
The are two identity operators in python.
- IS
- IS NOT
Python logic for IS NOT
a = 'java'
b = 'php'
print ('Output is true because a and b values not matches', a is not b)
Identical operators result in Boolean values – True/False. After you run the above logic, you will get True since a and b are distinct.

Python logic for IS
a1 = 'java'
b1 = 'java'
print ('Output is True because a1 and b1 values matches', a1 is b1)
Here the output will be True since both a1 and b1 are the same. So we will get True.

Membership operator
There are two membership operators in python. Those are in & not in.
- IN
- NOT IN
Python logic for IN
c = int(input("Enter the value"))
print ("The value of c is: " + format(c))
lst1 = [12,3,5,6,9]
if c in lst1:
print('c value is available in the list', c in lst1)
else:
print('c value is not available in the list', c in lst1)
The output is True since the value you enter is in the list. Here is the output.

Python logic for NOT IN
c = int(input("Enter the value"))
print ("The value of c is: " + format(c))
lst1 = [12,3,5,6,9]
if c in lst1:
print('c value is available in the list', c in lst1)
else:
print('c value is not available in the list', c in lst1)
The output is False since the value you enter is not in the list. Here’s the output.

I am sure the examples above provided differences between identical and membership operators in python.
Related posts
You must be logged in to post a comment.