preferred syntax for list extend?

Steve Holden sholden at holdenweb.com
Wed Apr 17 16:49:54 EDT 2002


"Ian Bicking" <ianb at colorstudy.com> wrote ...
>
> But that's weird...
>
> q1 += q3
> is not equivalent to:
> q1 = q1 + q3
>
It may be weird, but it's Python. Back when augmented assignment was being
discussed, I suggested that this might confuse newcomers, who would assume
that augmented assignment was merely a syntactic shortcut.

In many cases it is, but equally sometimes it isn't. The implementation of
any particular mutable object is free to perform in-place update for
augmented assignments, thus optimizing certain aspects of performance in
return for a modest amount of confusion.

While it might seem strange, rest assured that such is the language
designers' intent.

regards
 Steve







More information about the Python-list mailing list