Favorite non-python language trick?

Tim Peters tim.peters at gmail.com
Mon Jun 27 17:21:23 CEST 2005

[Terry Hancock]
> Probably the most pointless Python wart, I would think. The =/==
> distinction makes sense in C, but since Python doesn't allow assignments
> in expressions, I don't think there is any situation in which the distinction
> is needed.  Python could easily figure out whether you meant assignment
> or equality from the context, just like the programmer does.

That's what Python originally did, before release 0.9.6 (search
Misc/HISTORY for eqfix.py).  Even this is ambigous then:

    a = b

Especially at an interactive prompt, it's wholly ambiguous then
whether you want to change a's binding, or want to know whether a and
b compare equal.

Just yesterday, I wrote this in a script:

            lastinline = ci == ncs - 1


            lastinline = ci = ncs - 1

means something very different (or means something identical,
depending on exactly how it is Python "could easily figure out" what I
intended <wink>).

Of course strange rules could have resolved this, like, say, "=" means
assignment, unless that would give a syntax error, and then "=" means
equality.  Then

        lastinline = ci = ncs - 1

would have been chained assignment, and something like

        lastinline = (ci = ncs - 1)

would have been needed to get the intent of the current

        lastinline = ci == ncs - 1

More information about the Python-list mailing list