28

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

Python - Basic Operators 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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Pa1
  • 403
  • 1
  • 4
  • 6
  • 10
    `<>` 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

36

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
clemens
  • 16,716
  • 11
  • 50
  • 65
  • 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