Programming with Python

⌘K
  1. Home
  2. Docs
  3. Programming with Python
  4. Variables, Expression and...
  5. Operators and Types of Op...
  6. Identity Operators

Identity Operators

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)

Loading

Views: 1

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments