Python slang

Random832 random832 at fastmail.com
Fri Sep 2 11:13:50 EDT 2016


On Wed, Aug 10, 2016, at 12:19, Random832 wrote:
> On Wed, Aug 10, 2016, at 07:59, Dennis Lee Bieber wrote:
> >     The use of = also has a long history... FORTRAN (where the
> >     comparison was .EQ.), BASIC (granted, K&K required assignment to
> >     start with the keyword LET, so the use of = was mainly a
> >     delimiter between target and expression being assigned).
>
> Visual Basic actually uses = for both assignment and comparison
> *without* the Let keyword, it gets by on the fact that assignment is
> not an expression.

I just discovered something interesting. It turns out, Python 0.9.1 did
the same thing (i.e. = for both assignment and comparison), with the
ambiguity resolved by not allowing comparison operators generally in
some expression contexts.

>>> a, b = 1, 2 a < b
Parsing error: file <stdin>, line 1:
a < b
   ^
Unhandled exception: run-time error: syntax error
>>> # wait, what? I was doing this, originally, to test that comparisons
>>> # still worked after a change to cmp_outcome to silence a compiler
>>> # warning. I thought I'd somehow broken the parser.
>>> (a < b)
1
>>> (a = b)
0
>>> if a = b: 1 # It doesn't always need parentheses
... else: 0
...
0
>>> a, b
(1, 2)
 >>> (a == b) # Turns out the modern operator doesn't even exist
Parsing error: file <stdin>, line 1:
(a == b)
     ^
Unhandled exception: run-time error: syntax error
>>> (a != b) # And now something for Barry Warsaw
Parsing error: file <stdin>, line 1:
(a != b)
    ^
Unhandled exception: run-time error: syntax error
>>> (a <> b)
1

It's gone in Python 1.0 - all of the modern behavior we're familiar
with, except of course the boolean type, is fully present, with the
continued existence [for a while] of the <> operator the only trace of
days gone by.



More information about the Python-list mailing list