== 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 ifid(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.