Skip to content

Python not equal Operator | Number & String comparison

  • by

How to do a comparison of string and number in Python? Python, not an equal operator will check if two variables are of the same type and have different values. If they are the same then return or true else return false.

Python not equal Operator Number & String comparison

Python not equal Operators

If the values of the two operands are not equal, then the condition becomes true. See below syntax:-

  • != (a != b) is true.
  • <> (a <> b) is true. This is similar to != operator.

Python not equal Examples

Example using !=

Here is 2 example first is only if condition statement and another one using if-else condition statements.

# first example
if 1 != 10:
    print("1 is not equal to 10");

# second example
if 1 != 1:
    print("1 is not equal 1");
else:
    print("1 equal 1");

Output:

1 is not equal to 10
1 equal 1

Example using <>

<> is not removed from Python 3.

# first example
if 1 <> 10:
    print("1 is not equal 10");


Output: Error screenshot

Python not equal error on 3

Do comment if you have any doubts and suggestions on this tutorial.

Note: This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JRE: 1.8.0
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.13.6
Python 3.7
All Python Programs are in Python 3, so it may change its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *