MWZ

MINDWAREZONE

beginnerPython

What is the difference between == and is?

Answer

Clear, interview-ready explanation

The == operator compares the values of two objects, while the is operator checks whether two references point to the same object in memory.  

first = [1, 2, 3]
second = [1, 2, 3]

print(first == second)
print(first is second)
            

Output:

True
False
            

The lists contain equal values, but they are separate objects.

Use:

  • == to compare values.
  • is to compare object identity.

The is operator is commonly used when checking for None:

if result is None:
    print("No result is available")
            

  Do not use is to compare strings or numbers because object reuse is an implementation detail and may produce misleading results.