Not equal operator in Python

Python has a number of basic operators that include some comparison operators, too. A comparison operator compares the values on both sides of the operator to classify the relation between them as either true or false.


Not equal operator

One important basic comparison operator, in Python, is the not equal operator. The two operators that can be used to perform the not-equal comparison in Python are shown below:

  • !=
  • <> (deprecated)

If the values of the two operands (any valid Python objects) given on each side of the operator are not equal, then the condition returns true, otherwise false.

Python `not-equal` operators
Python `not-equal` operators

Example

Here are some examples that show how to use the != operator

print('[] != [] evaluates to: ', [] != [])
print('10 != 15 evaluates to: ', 10 != 15)
print('{\'a\': 1} != {\'a\': 1} evaluates to: ' , {'a': 1} != {'a': 1})

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved