What is the difference between is and == in Python?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Python development. It reveals whether you understand the building blocks that more complex concepts rely on.
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.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.