EasyExperience level: 0-2 years · 3-5 years1 min read

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

Reviewed by Gurusankar M.

Asked inInfosysWiproAccentureCapgemini
#is#equality#identity#none#python basics
Report issue

Short Answer

`==` compares values (are they equal?); `is` compares identity (are they the exact same object in memory?). Use `==` for value checks and reserve `is` for singletons like `None`, `True`, `False`. Two equal objects can be different objects, so `==` can be True while `is` is False.

On this page

Concept Made Simple

Coffee Chat Question

“What is the difference between `is` and `==` in Python?”

Remember It Faster

Mind Map Answer

==
value equality (calls __eq__)
is
same object (same id)
Rule
use `is None`, `==` for everything else

Learn by Doing

Hands-on Keyboard

python
a = [1, 2, 3]
b = [1, 2, 3]
print(a == b)   # True  - same values
print(a is b)   # False - different objects

x = None
print(x is None)  # correct None check
Output
True
False
True

Think Beyond the Expected

What If?

Why does `a is b` sometimes return True for small integers but not large ones?

CPython caches (interns) small integers (-5 to 256) and short strings, so identical literals may share one object — making `is` accidentally True. That's an implementation detail, not a guarantee. Never rely on `is` for value comparison; always use `==`.

Real World

The classic bug is `if x is 0` or `if name is 'admin'` — it works in tests thanks to interning, then fails in production on a computed value. Linters flag `is` with literals for exactly this reason.

Interviewer's Expectation

Keywords they're listening for:

  • == value, is identity
  • use `is None`
  • equal ≠ same object
  • integer/string interning caveat
  • don't use `is` for literals

Common Mistakes

  • Using `is` to compare values/literals
  • Writing `== None` instead of `is None`
  • Relying on small-int caching behavior

Best Practices

  • Use `==` for value equality
  • Use `is` only for None/True/False/singletons
  • Let linters catch `is` with literals

Follow-up Questions

  1. Why is `is None` preferred over `== None`?
  2. What is string/int interning?
  3. How does overriding __eq__ affect ==?

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Data Types (Python)
Interview question: "What is the difference between `is` and `==` in Python?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.