What is the difference between == and is in Python?

The == operator checks if two values are equal. The is operator checks if two names point to the same object in memory.

a = [1, 2, 3]
b = [1, 2, 3]
c = a

print(a == b)
print(a is b)
print(a is c)

Output:

Tutorials Class - Output Window

True
False
True

a and b have the same values but are two separate lists. c is just another name for the same list as a. Use == to compare values, and use is mainly for None, like if x is None:. See Python Operators.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.