Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a difference between != and <> operators in Python?

Tags:

I tried searching but could not find much about the <> operator.

https://www.tutorialspoint.com/python/python_basic_operators.htm mentions that <> is "similar" to the != operator and does not say what is different or how it is different.

My tests seem to show it is the same:

a = 2, b = 3 >>> a != b True >>> a <> b True >>> b = 2 >>> a != b False >>> a <> b False 

Any help to understand this would be appreciated.

like image 214
Pa1 Avatar asked Oct 24 '16 05:10

Pa1


People also ask

What is the use of <> in Python?

or <> . Both stands for not equal. [Reference: Python language reference] The comparison operators <> and != are alternate spellings of the same operator. !=

What does != operator mean in Python?

Not equal to - True if operands are not equal. x != y. >= Greater than or equal to - True if left operand is greater than or equal to the right. x >= y.

What is the difference between <> and not operator?

Both operators give the same output. The only difference is that '<>' is in line with the ISO standard while '!= ' does not follow ISO standard. You should use <> operator as it follows the ISO standard.

What is the difference between != and == in Python?

The = is a simple assignment operator. It assigns values from right side operands to the left side operand. While on the other hand == checks if the values of two operands are equal or not. If yes, the condition becomes true and it returns a non zero value.


1 Answers

The python documentation says that they are equivalent.

The comparison operators <> and != are alternate spellings of the same operator. != is the preferred spelling; <> is obsolescent.

The <> operator has been removed from Python 3.

like image 162
clemens Avatar answered Nov 06 '22 02:11

clemens