
However, there are some nuanced differences. In this example, it may seem that these perform the same function. Let’s take a look at an example: # Comparing != and not in Python There are some key differences here, however. It may seem that we can use the not equal operator in Python interchangeably with the not keyword. One of the great things about Python is the ability to use plain-English words to write your code. Python Not Equal Operator Versus Not Keyword != is available in both Python 2 and Python 3īecause the operator has been deprecated in Python 3, to future proof your code (if you’re still running Python 2), it’s better to use !=.Python 2 had two not equal operators available:

The equality operator checks for equality and will return a True if the values are equal to one another.

The expression represents the inverse of the equality operator, =. Because that’s not the case, the expression returns True. We can see that when we evaluate whether or not 1 is equal to 2. Let’s take a look at an example: # A Basic Example of the Not Equal Operator

The Python not equal operator is written as != and returns a boolean value evaluating if the expressions are not equal. Multiple Conditions for Python Not Equal.
#Python while loop python not equal how to
