Using == and is for Comparisons in Python


Understand the difference between == (equality) and is (identity).

Source Code

# `==` checks if values are equal
# `is` checks if objects are the same (identity)
a = [1, 2, 3]
b = a
print(a == b)  # True
print(a is b)  # True

c = a[:]
print(a == c)  # True
print(a is c)  # False
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments