Table of Contents
show
Identity operators are used to compare the objects, not if they are equal, but if they are actually the same object, with the same memory location
Example
x="Python"
y="Python"
x1=["python"]
y1=["python"]
x2=5
y2=5
print("x is y", x is y)
print("x1 is not y1", x1 is not y1)
print("x2 is not y2", x2 is not y2)
z2=x2
print("z2 is x2",z2 is x2)
print("x2 is not y2",x2 is not y2)
print("x2!=y2",x2 != y2)
print("x1 is y1",x1 is y1)
print("x1 == y1",x1==y1)
Output
('x is y', True)
('x1 is not y1', True)
('x2 is not y2', False)
('z2 is x2', True)
('x2 is not y2', False)
('x2!=y2', False)
('x1 is y1', False)
('x1 == y1', True)
Views: 1