== Equal
Last updated: 2026-09-22
== Equal
== tests equality (delegated to __eq__).
| Category | Operators |
|---|---|
| Kind | Operator |
| Python Version | all |
📝 Syntax
a == b
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
True
True
False
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat is the difference between == and is?
A`==` compares whether two objects' values are equal (decided by `__eq__`); `is` compares whether they are the same object (same `id`). With `a = [1, 2]; b = [1, 2]`, `a == b` is `True` but `a is b` is `False`.
QWhen a custom class does not define __eq__, what does == do?
ABy default it compares object identity, equivalent to `is`: two objects are equal only if they are the same instance. To define value equality, implement `__eq__`, and usually also define `__hash__`.
QWhy is '1' == 1 False?
ABecause `==` does no implicit type conversion; a string and an integer are never equal. To compare, convert explicitly, e.g. `int('1') == 1`.