Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. == vs is

Python · Collections & Basics

== vs is

Easypython-04
equalityidentitynoneoperators

Question

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

Solution

== compares value equality. is compares object identity (whether two names point to the exact same object in memory).

  • a == b → True if values are equal (calls __eq__ under the hood).
  • a is b → True if id(a) == id(b).

Use is for singletons like None (x is None). Prefer == when comparing numbers, strings, lists, or domain values.

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

print(a == b)   # True  (same contents)
print(a is b)   # False (different list objects)
print(a is c)   # True  (same object)

x = None
print(x is None)     # preferred
print(x == None)     # works, but style guides prefer "is"

# Interning can make small ints / short strings share identity,
# but you must not rely on that for correctness.
print(256 is 256)    # often True
print(257 is 257)    # may be False depending on context
print(257 == 257)    # always True

Pitfall: Do not use is to compare strings or numbers for business logic. Interning and caching make identity checks unreliable across Python versions and runtimes.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext