Special Operators

Special Operators

Python language offers following 2 special operators.

  1. Identity Operators
  2. Membership operators
1. Identity Operators
  • We can use identity operators for address comparison.
  • There are 2 identity operators are available
    • is
    • is not
  • r1 is r2 returns True if both r1 and r2 are pointing to the same object.
  • r1 is not r2 returns True if both r1 and r2 are not pointing to the same object.
a=10
b=10 
print(a is b) ==> True 

x=True
y=True 
print( x is y) ==> True
x = 'Waytoeasylearn'
y = 'Waytoeasylearn'
a = [10,20,30]
b = [10,20,30]

print(x is y) ==> True

# Output: False
print(a is b) ==> False

Note

We can use is operator for address comparison where as == operator for content comparison.

2. Membership Operators
  • We can use Membership operators to check whether the given object present in the given collection. (It may be String, List, Set, Tuple OR Dict)
  • In ==> Returns True if the given object present in the specified Collection
  • not in ==> Returns True if the given object not present in the specified Collection.

E.g

x="Waytoeasylearn" 
print('e' in x) True 
print('d' in x) False 
print('d' not in x) True 
print('learn' in x) True
Special Operators
Scroll to top