preferred syntax for list extend?

Alex Martelli aleax at aleax.it
Wed Apr 17 17:22:14 EDT 2002


Joshua Marshall wrote:
        ...
>> If it were, there would be little reason for it to exist -- saving
>> a couple of keystrokes would be a silly reason to introduce a
>> bunch of new operators.
> 
> To me there's a more compelling reason for the existence of "+=": you
> don't need to use a temporary variable to prevent the lvalue from being
> computed twice. Eg:

But the "temporary variable" IS a couple of keystrokes.  Since it's
only a reference that's copied to the temp, cost difference is truly
minute anyway.

> Granted, since in Python assignment is a statement and not an expression,
> this is less of a win than the existence of += in C, where it might be
> inconvenient to introduce a temporary.

It's such a tiny 'win' in Python, that it would not justify += and friends.
_Just a couple of keystrokes_...!  Almost doubling the number of operators
in a language for THAT?!  No, it's only the NON-equivalence of a+=b to
a = a + b that made introducing += &c really sensible.


Alex




More information about the Python-list mailing list