What is identical operator and how to use identical operator
Using identical operator
Use == to see if two objects are equal, and use is to see if they are identical (the same object).
x = y = [1, 2, 3]# from w ww. jav a 2 s .c o m
z = [1, 2, 3]
print x == y
print x == z
print x is y
print x is z
print "foo" == "foo"
print "foo" == "bar"
The code above generates the following result.
is not
x = [1, 2, 3]
y = [2, 4]
x is not y
Standard Type Object Identity Comparison Operators
a = [ 5, 'hat', -9.3]
b = a# ww w. jav a 2 s. c om
print a is b
print a is not b
b = 2.5e-5
print b
print a
print a is b
print a is not b
The code above generates the following result.