syntax – What does `<>` mean in Python?
syntax – What does `<>` mean in Python?
It means not equal to. It was taken from ABC
(pythons predecessor) see here:
x < y, x <= y, x >= y, x > y, x = y, x <> y, 0 <= d < 10
Order tests (
<>
means not equals)
I believe ABC
took it from Pascal, a language Guido began programming with.
It has now been removed in Python 3. Use !=
instead. If you are CRAZY you can scrap !=
and allow only <>
in Py3K using this easter egg:
>>> from __future__ import barry_as_FLUFL
>>> 1 != 2
File <stdin>, line 1
1 != 2
^
SyntaxError: with Barry as BDFL, use <> instead of !=
>>> 1 <> 2
True
It means NOT EQUAL, but it is deprecated, use !=
instead.
syntax – What does `<>` mean in Python?
Its worth knowing that you can use Python itself to find documentation, even for punctuation mark operators that Google cant cope with.
>>> help(<>)
Comparisons
Unlike C, all comparison operations in Python have the same priority,
which is lower than that of any arithmetic, shifting or bitwise
operation. Also unlike C, expressions likea < b < c
have the
interpretation that is conventional in mathematics:Comparisons yield boolean values:
True
orFalse
.Comparisons can be chained arbitrarily, e.g.,
x < y <= z
is
equivalent tox < y and y <= z
, except thaty
is evaluated
only once (but in both casesz
is not evaluated at all whenx <
is found to be false).
yThe forms
<>
and!=
are equivalent; for consistency with C,
!=
is preferred; where!=
is mentioned below<>
is also
accepted. The<>
spelling is considered obsolescent.
See http://docs.python.org/2/reference/expressions.html#not-in