Skip to main content

Identity (is) vs equality (==) and hashing rules

Distinguish is from ==, explain small-integer/string interning traps, and state the hashable invariant.

Official Reference

Model Answer & Explanation

is checks object identity (id(a) == id(b)), whereas == invokes __eq__ for value equality. Always use is only for singletons like None, True, False—never for numbers or strings where interning behavior is an implementation detail. Equal objects (a == b) must produce identical hashes (hash(a) == hash(b)), which is why mutable containers like list/dict are unhashable.

Follow-up Interview Question · Why does Python set __hash__ = None automatically when a class defines __eq__?

Module Context & References

Python & FastAPI · Popular interview theory The 20% of Python & FastAPI concepts asked in 80% of backend interviews
Personal Notes · Markdown

Technologies & Interview Topics Covered

Switch between short-term interview tracks and long-term 80/20 engineering depth to practice JavaScript internals, React rendering and hooks, timed frontend machine coding UI challenges, MeetaPro FG300, Blind 75 & NeetCode 150 DSA patterns, Python & FastAPI APIs, PostgreSQL query optimization & MVCC, Redis caching, Applied AI RAG pipelines & evaluations, and distributed system design.