What is the meaning of <> in Python?
I have tried searching for it on Google but I cannot seem to get inside the search term...
I have not seen this in any other language also otherwise开发者_如何学JAVA I would have tried to find it.
<>
is an alternate spelling of !=
, the inequality test operator. IIRC, it has been removed in Python3.
>>> "foo" <> "bar"
True
>>> "foo" <> "foo"
False
It is an obsolete inequality operator. See the Python documentation.
!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only. New code should always use !=.
<>
means not equal to
. <>
and !=
have the same meanings.
From the docs:
The forms <> and != are equivalent; for consistency with C, != is preferred; where != is mentioned below <> is also accepted. The <> spelling is considered obsolescent.
It is the same as != ("not equal")
the <> operator is the same as != which means not equal to
if thing1 <> thing2:
code here
精彩评论