orokusaki
orokusaki

Reputation: 57118

Python ( or general programming ). Why use <> instead of != and are there risks?

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.

Upvotes: 5

Views: 516

Answers (3)

Alex Martelli
Alex Martelli

Reputation: 881487

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

Upvotes: 15

Mark Dickinson
Mark Dickinson

Reputation: 30561

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.

Upvotes: 8

SilentGhost
SilentGhost

Reputation: 319531

you shouldn't use <> in python.

Upvotes: 0

Related Questions