Augmented Assignement (was: Re: PEP scepticism)

David Bolen db3l at fitlinxx.com
Fri Jun 29 17:24:00 EDT 2001


Carsten Geckeler <uioziaremwpl at spammotel.com> writes:

> The problem which some people have with augmented assignment is not that
> they exist, but that they do not work as they expect (at least from the
> POV of some readers).  I expect that
> 	ident op= expr
> works like
> 	ident = ident op expr
> 
> At least that's what I'd have expectd comming from other programming
> languages.

Of course, one interesting point is that while you may think the above
if coming from, say, C, what "ident = ident op expr" means in C is not
what "ident = ident op expr" means in Python.

In C it has the result of changing data (in either case) that is
stored in a named location ident, in Python the long form just rebinds
the reference ident to a new object and doesn't touch the original
object.  The short form can actually get closer to the C idiom if the
object is mutable.

So I wonder if some of the confusion is people familiar with other
language's augmented assignment trying to extrapolate that into Python
and then running into the pre-existing differences in assignment
versus binding?

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list