'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

== compares values; 'is' compares identity, meaning whether two names point to the very same object in memory. Use == for values and 'is' only for None, True and False.

The concept

Two separate lists with the same contents are equal (==) but not identical (is). Python gives each object an id, and 'is' compares those ids.

Small integers and some strings are cached, so 'is' can look like it works and then fail on larger values. That behaviour is an implementation detail you should not rely on.

Same value, different object

a = [1, 2]; b = [1, 2]; c = a
a == b, a is b, a is c
True, False, True
x = None; x is None
True

Practical examples

Correct None check

if result is None:
    print('no result')

Value comparison

if name == 'admin':
    grant()

The caching trap

a = 256; b = 256
a is b   # True (cached)
a = 1000; b = 1000
a is b   # may be False — don't depend on it

Common mistakes

  • Using 'is' to compare numbers or strings.
  • Using == None instead of 'is None' (custom __eq__ can fool it).
  • Assuming copies are identical objects.

Key takeaways

  • == = same value, is = same object.
  • Use 'is' for None/True/False.
  • Never rely on small-object caching.

FAQ

How can I see an object's identity?

Call id(obj); 'is' compares those ids.

Why does 'a is b' sometimes work for strings?

CPython interns some strings. It is an optimisation, not a guarantee.

More Python articles