'is' vs '==' in Python — What's the Difference?

== compares values for equality; 'is' compares object identity. Learn why 'is' should almost never be used for value comparison, with None as the exception.

Published September 17, 2026

== checks whether two objects have equal values (by calling __eq__). 'is' checks whether two variables refer to the exact same object in memory (identity), regardless of whether their values happen to be equal.

Common causes

  • Small integers and short strings are often cached and reused by CPython, which can make 'is' appear to work for value comparison by coincidence — but this behavior isn't guaranteed by the language

How to fix it

  • Use == for comparing values — this is almost always what you actually want (numbers, strings, lists, custom objects)
  • Use 'is' only for identity checks — most commonly comparing against None, True, or False, or checking if two variables point to the same object
  • Never rely on 'is' for integer or string equality — it can appear to work for small values due to CPython's internal caching but will fail unpredictably for larger ones

Example

a = [1, 2, 3]
b = [1, 2, 3]
a == b  # True  — same values
a is b  # False — different objects in memory

x = None
x is None  # True — correct idiom for None checks

FAQ

Why does `x is None` work but `x is 1000` sometimes fail?

None is a true singleton — there is only ever one None object. Integers outside CPython's small-int cache range (-5 to 256) are not guaranteed to be the same object even if equal in value.

More Python articles