Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between != and <>? [duplicate]

Perhaps this is a rather newbie-ish question, but I'm curious. I have tried searching for it, but I suppose I lack the correct terminology to search properly.

Difference between != and <>.

On searching again, "inequality", I found one that discusses not == and !=, but nothing about <>.

like image 200
francium Avatar asked Dec 26 '13 22:12

francium


People also ask

What's the difference between != And !==?

!= will only check value regardless of operands type. but !== is used to compare both value & type of 2 operands that are being compared to each other.

What is != And !== In JavaScript?

==) The strict inequality operator ( !== ) checks whether its two operands are not equal, returning a Boolean result.

What is the difference between == and === comparison?

The == operator checks if two values are equal. The != operator checks if two values are not equal. It is also known as the loose equality operator because it checks abstract equality, i.e., it tends to convert the data types of operands in order to carry the comparison when two operands aren't of the same data type.

What does the === comparison do?

=== (Triple equals) is a strict equality comparison operator in JavaScript, which returns false for the values which are not of a similar type. This operator performs type casting for equality. If we compare 2 with “2” using ===, then it will return a false value.


2 Answers

They are interchangeable in Python 2, but <> is deprecated and has been removed in Python 3.

Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win32
>>> 1 <> 2
True
>>> 1 != 2
True

Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
>>> 1 <> 2
  File "<stdin>", line 1
    1 <> 2
       ^
SyntaxError: invalid syntax
>>> 1 != 2
True
like image 171
Tim Pietzcker Avatar answered Sep 22 '22 12:09

Tim Pietzcker


In Python 2.x, <> is equivalent to !=, as described in the documentation:

The forms <> and != are equivalent; for consistency with C, != is preferred; where != is mentioned below <> is also accepted. The <> spelling is considered obsolescent.

In Python 3.x, <> has been removed. Again, the documentation says:

Removed Syntax

....

Removed <> (use != instead).

like image 33
David Heffernan Avatar answered Sep 21 '22 12:09

David Heffernan