5
votes

I think if I understand correctly, a <> b is the exact same thing functionally as a != b, and in Python not a == b, but is there reason to use <> over the other versions? I know a common mistake for Python newcomers is to think that not a is b is the same as a != b or not a == b.

  1. Do similar misconceptions occur with <>, or is it exactly the same functionally?
  2. Does it cost more in memory, processor, etc.
3
@S.Lott It got voted up didn't it. Why are you so hostile. Look, Alex Martelli, an expert who has written successful published books took the time to answer it. - orokusaki

3 Answers

15
votes

<> in Python 2 is an exact synonym for != -- no reason to use it, no disadvantages either except the gratuitous heterogeneity (a style issue). It's been long discouraged, and has now been removed in Python 3.

8
votes

Just a pedantic note: the <> operator is in some sense misnamed (misdenoted?). a <> b might naturally be interpreted as meaning a < b or a > b (evaluating a and b only once, of course), but since not all orderings are total orderings, this doesn't match the actual semantics. For example, 2.0 != float('nan') is true, but 2.0 < float('nan') or 2.0 > float('nan') is false.

The != operator isn't subject to such possible misinterpretation.

For an interesting take (with poetry!) on the decision to drop <> for Python 3.x, see Requiem for an operator.

0
votes

you shouldn't use <> in python.