Interview frequency: …
Short answer
== compares values through __eq__, while is checks whether two names refer to the same object in memory (the same identity, id).
Explanation
Use is with unique objects (singletons) such as None, True, False and sentinel objects, and use == to compare values. CPython caches small integers (-5 to 256) and some strings (interning), so is may return True by coincidence for equal values; these are implementation details, not guarantees, and recent versions emit a SyntaxWarning when you compare a literal with is.
Code example
a = [1, 2]
b = [1, 2]
print(a == b) # True — Same value
print(a is b) # False — Two different objects
if value is None:
...Common mistakes
- Writing if x is 1000 or if name is "admin" and relying on caching that is not guaranteed.
- Writing if x == None instead of if x is None.