Trusted answers to developer questions

Not equal operator in Python

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

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})

RELATED TAGS

python
comparison
operators
equality
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?