Back to Top

Python Identity Operator Example


Identity Operator

It is used to compare the object of two different variables.

We can also check the identity of an object using id().

Program
x = ["fresherbell", "tutorial"]
y = ["fresherbell", "tutorial"]
z=x;
print(x is z) #return true because x is the same object as z
print(x is y) #return false because x is not the same object as y
print(x is not z) #return false because x is the same object as z
print(x is not y) #return true because x is not the same object as y
print(id(x))
print(id(y))
print(id(z))
a = 'Sam'
b = 'Sam'
print(a is b) #True - reason is A-Z, a-z, 0-9, _ is applicable in String
a = 'Sam#'
b = 'Sam#'
print(a is b) #False - reason is A-Z, a-z, 0-9, _ is applicable, but # is not applicable in String
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Input
Output