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

34,035

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.

Share:
34,035

Related videos on Youtube

Pa1
Author by

Pa1

Updated on October 24, 2020

Comments

  • Pa1
    Pa1 over 3 years

    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.

  • T.J. Crowder
    T.J. Crowder over 7 years
    ...and <> isn't mentioned in the v3 documentation at all.
  • Pa1
    Pa1 over 7 years
    @ T.J. Crowder: Thanks for the clarification about the 2.x and 3.x difference as well.
  • sarnthil
    sarnthil about 6 years
    you can still use it Python 3: from __future__ import barry_as_FLUFL
  • NoName
    NoName over 4 years
    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.
  • clemens
    clemens over 4 years
    @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.