Why prefer != over <> for Python 3.0?

Lie Lie.1296 at gmail.com
Sat Mar 29 13:34:35 EDT 2008


On Mar 29, 5:55 pm, kwitt... at telenet.be wrote:
> I don't know if this is the right place to discuss the death of <> in
> Python 3.0, or if there have been any meaningful discussions posted
> before (hard to search google with '<>' keyword), but why would anyone
> prefer the comparison operator != over <>???
>
> I've written an article about it to try and save this nice "is not
> equal" operator, located athttp://dewitters.koonsolo.com/python_neq.html
>
> Please set it straight in 3.0, and if not, convince me with a good
> reason of doing so, so that I can live with it and don't have to spend
> the rest of my life in 2.x ;).

<quote who=OP's blog>
All pretty clear hey? But now comes the catch, there exists an
operator !=... but what does it mean? Well, that one is pretty easy,
of course ! must be an operator of its own (in non-python languages
meaning 'not'), and it resembles the fancy assignment statement
<...snip...>

When I started to learn python I came across an operator <>. What
could it mean? Well, you don't have to think long about it. You're
only reference are the < and > operators (with meanings the same as in
mathematics or plain written language, any non programmer would
understand this). So <> must mean "smaller or larger", or not-equals,
no question about that. It couldn't possible be mistaken as an
assignment operator. You just have to love a language that uses
operators with clear and obvious meaning.
</quote>

You're forcing your argument too much, both != and <> are NOT standard
mathematics operators -- the standard not-equal operator is >< -- and
I can assure you that both != and <> won't be comprehensible to non-
programmers. And I'm not sure if anyone could have mistaken != for
assignment operator because they're used in completely different
places (which is the reason why some languages can use the same
operator for = (assignment) and == (comparison)). = is always used in
a line by itself while != is always used in places where a
'condition' (a.k.a. 'expression') is required.

The problem you stated may be a problem in C/C++ (if C/C++ do have
both != and <>, fortunately they only have !=) because C/C++'s =
(assignment) is an operator and operators always return a value but in
Python = (assignment) is a statement and can't return a value so "if a
= b:" always raise an error.

Since != operator can only be used in places where a
'condition'/'expression' is required and never in a line by itself as
a statement, it could never be mistaken as an assignment (which is a
statement).

The problem just don't exist in Python.



More information about the Python-list mailing list