🐍 Python
Beginner
What is the difference between is and == in Python?
Answer
In Python, == checks value equality — whether two objects have the same value. is checks identity — whether two variables point to the exact same object in memory (same id()). Example: a = [1, 2, 3]; b = [1, 2, 3]; a == b is True (same values), but a is b is False (different objects). However: a = b = [1, 2, 3]; a is b is True (same object). Due to Python's small integer caching and string interning, is may return True for small integers and some strings — but rely on this only for singletons: x is None, x is True, x is False. Always use == None vs is None — use is None.