!= Not equal
Last updated: 2026-09-22
!= Not equal
!= is the negation of ==.
| 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
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QDoes != do type conversion?
ANo. `'1' != 1` is `True`. Like `==`, it is a strict comparison with no implicit conversion.
QIf a custom class defines only __eq__ and not __ne__, what happens?
AIn Python 3, when `__ne__` is missing it is automatically derived by negating `__eq__`, so defining `__eq__` is usually enough.
QAre != and not (a == b) completely equivalent?
AFor the vast majority of types, yes. But a very few classes define an inconsistent `__ne__`, in which case they may differ; it is safer to consistently use `!=`.