Why prefer != over <> for Python 3.0?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sat Mar 29 07:41:17 EDT 2008
On Sat, 29 Mar 2008 04:08:16 -0700, Paul Rubin wrote:
> kwitters at telenet.be writes:
>> 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 doubt anyone cares.
[channeling Luke Skywalker sotto voice]
I care.
> Python probably chose != because it's what C uses.
Coming from a background in Pascal, I originally hated the look of != and
preferred <> but I've now got used to the look of it.
When I design my own language (ha!), I'll use != for "not equal to" and
reserve <> for "greater than or less than but not equal to" which is
subtly different. (Think about unordered values, where x != y does not
imply that x < y or x > y, e.g. IEEE NaNs.)
> The scary choice is /= which can be interpreted as an assignment.
"Can be"?
>>> x = 5.0
>>> x /= 2
>>> x
2.5
Koen, I've read your blog and I'm afraid that your reasoning is specious.
You say:
[quote]
For comparison (not assignment!), they use operators like <, >, <=
(smaller or equals), >= (larger or equals), == (double '=' so there is no
confusion with assignment).
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, so
a != b
must mean "assign the value 'not b' to 'a'... right?... Wrong! Somehow
this is a comparison operator meaning "not equals"... what??? Yes, that's
right, but hey, you learn to live with it eventually.
[end quote]
Given that <= is a comparison operator, not an assignment, why do you
jump to the conclusion that != is an assignment? Why don't you argue that
"x <= y" means "assign the value of x<y to x"?
Since you jump to an invalid conclusion about !=, the rest of your
argument fails.
--
Steven
More information about the Python-list
mailing list