is Identity test
Last updated: 2026-09-22
is Identity test
is tests identity (same object in memory).
| Category | Operators |
|---|---|
| Kind | Operator |
| Python Version | all |
📝 Syntax
a is b
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
True
False
💡 Tip Use `is None` / `is not None`; do not compare None with `==`.
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhy is the result of `is` unstable when comparing integers?
ACPython caches small integers (-5 to 256), so identical literals are usually the same object. Outside that range, whether objects are reused is not guaranteed and may vary with implementation and compiler optimizations. Always use `==` to compare numbers.
QWhen should I use is?
AOnly two scenarios: checking for `None` (`x is None` / `x is not None`), and comparing `True`/`False` or custom singletons. To compare content equality, always use `==`.
QWhen a custom class doesn't implement __eq__, are == and is the same?
AYes. The default `==` degenerates to identity comparison (equivalent to `is`). But as soon as you define `__eq__`, the two may differ.