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.
or <> . Both stands for not equal. [Reference: Python language reference] The comparison operators <> and != are alternate spellings of the same operator. !=
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With