Re: Why prefer != over <> for Python 3.0?



On Mar 29, 5:55 pm, kwitt...@xxxxxxxxxx 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.
.



Relevant Pages

  • Re: Finding the instance reference of an object
    ... works in Python, all you need to know then is that parameters are ... Then you don't know about all that many languages. ... these same semantics for assignment. ...
    (comp.lang.python)
  • Re: why cannot assign to function call
    ... When dealing with objects in C++, one routinely handles them with pointers, so that's the use case which is analogous to Python -- all the value types can be ignored for the sake of comparison. ... Python's assignment semantics, and further appear ... They already understand some other language, and then they come here and read wild claims that Python's assignment and parameter-passing semantics are different from other languages. ...
    (comp.lang.python)
  • Re: why cannot assign to function call
    ... understand how assignments work in these languages, ... as in Python, Java, REALbasic, .NET, etc. ... Arrays are the only datatype in C that don't use ... Python's assignment semantics, and further appear ...
    (comp.lang.python)
  • Re: Nested function scope problem
    ... It may be the case in a number of languages but my ... Python names are ... through various means (most commonly assignment). ... In languages like Lisp, ...
    (comp.lang.python)
  • Re: Finding the instance reference of an object
    ... call semantics in the Python community than in the community of other ... Call by value already has at least one well-established meaning. ... In such languages as Pascal and C, a variable such as x refers to a fixed ...
    (comp.lang.python)