Is it just Syntactic Sugar ?
speed at ?.com
Tue May 23 14:31:52 CEST 2000
thomas at xs4all.net (Thomas Wouters) wrote in
<20000523090202.V13281 at xs4all.nl>:
>However, the main reason for this patch is *not* speed... Speed is a
>minor issue, in Python design. The main rason for augmented assignment
>is to provide a convienent and obvious way for mutable objects to be
>MyLargeOBject = MyLargeObject + 1
>Creates a new instance of MyLargeObject, copying all data, and then adds
>one to it. Unless you override __add__ in MyLargeObject to avoid that,
>but then you can never do:
>MyOtherObject = MyLargeObject + 1
>without modifying MyLargeObject as well. The += syntax is very good for
>this, as you can be totally sure the programmer wants you to modify the
>object, not create a new, modified copy.
So we have:
a = 3
a += 2 # assignment / symbol binding
a = Object()
a += 2 # expression / method call
a += 2 # ??????
More information about the Python-list