26

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.

user2864740
  • 57,407
  • 13
  • 129
  • 202
Pa1
  • 383
  • 1
  • 3
  • 6
  • 9
    `<>` is deprecated and removed in python 3 http://stackoverflow.com/questions/11060506/is-there-a-not-equal-operator-in-python – ymonad Oct 24 '16 at 05:35

1 Answers1

35

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.

user2864740
  • 57,407
  • 13
  • 129
  • 202
clemens
  • 15,334
  • 11
  • 41
  • 58
  • 1
    ...and `<>` isn't mentioned in the [v3 documentation](https://docs.python.org/3/reference/lexical_analysis.html#operators) at all. – T.J. Crowder Oct 24 '16 at 05:34
  • 1
    @ T.J. Crowder: Thanks for the clarification about the 2.x and 3.x difference as well. – Pa1 Oct 24 '16 at 05:55
  • 1
    you can still use it Python 3: `from __future__ import barry_as_FLUFL` – sarnthil Feb 16 '18 at 09:33
  • Any one know the historical reason for including <> as "not equal" in the first place? Never have I seen this operator before, in math or programming. – NoName Jan 03 '20 at 19:52
  • 2
    @NoName: Pascal uses <> as not equal operator, and it is simply a concatenation of lower and greater operator. You may read it as *lower or greater than*. This is in the context of Pascal equivalent to not equals. Many SQL dialects support both operators, too. – clemens Jan 03 '20 at 20:32