Python Source Code Beautifier

greg greg at cosc.canterbury.ac.nz
Sat Mar 3 05:34:35 CET 2007


Alan Franzoni wrote:
> I would assume then, that if the '+=' operator
> is assumed to modify objects in-place, it would just fail on immutable
> objects, wouldn't I?

Then you wouldn't be able to do things like

    x = 3
    x += 1

which would result in howls of outrage from the
*other* half of the Python community.

The x += y syntax is designed to fill two different
but equally useful roles: one is to modify objects
in-place, the other is to be a short hand for
x = x + y.

This was all discussed at *very* great length many
years ago, and the addition of in-place operators
to the language was held up for a long time until
the present compromise was devised. You might not
like it, but it's here to stay.

--
Greg



More information about the Python-list mailing list