Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
comparison
operators
equality

Not equal operator in Python

Educative Answers Team

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.

svg viewer
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 ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring