How To Use Not Equals To Operator Using Python

In this tutorial, learn how to use the not equals to operator in Python. The short answer is to use the operator != to add not equals to in Python. When using an if conditional statement in Python, you may require to put a not matching comparison operator.

You may think of other popular programming languages like Java and C++. Don’t make any mistake in using the same operator !== on your coding. Python has some different ways to write this not matching comparison operator.

But what are the way to write this operator and use on your coding? Well, here are some examples you can check and find those easiest ways. You can change or modify the examples as per your requirement.

So, let’s start writing your code with the not equals to the operator.

How to Use Not Equals to Operator in Python

The operator can be used with the if conditional statement in Python. You can use the condition inside the loop or without the loop. This operator returns true when the two values are different or not the same.

To use this operator, you have to use != in Python coding. This operator requires a single equal to(=) operator to write. See the example below to create your own code with this operator.

Output

N
a
t
i
n

The above example prints all the characters of the string which are not matching with “o”. Upon execution of each iteration of the loop, a single string character gets printed in a single line.

I hope you like this post of how to use the comparison operator not equals to in Python.