is vs == (Python)

== checks whether two values are equal, while is checks whether two variables point to the exact same object in memory. They are not interchangeable.

Python

Use == for value comparisons (like numbers and strings) and reserve is for checking against None, True, and False. Two equal-looking objects can be == but not is.

Examples

Python

a = [1, 2]
b = [1, 2]
print(a == b)
print(a is b)

Output:

True
False

See also

Back to the Dictionary