Search code examples
pythonsyntaxequalityinequality

What is the difference between != and <>?


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 <>.


Solution

  • 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).