Python 2.0b1 is released!

Alex Martelli aleaxit at
Fri Sep 8 16:05:35 CEST 2000

"Toby Dickenson" <mbel44 at> wrote in message
news:n2khrso0khf70shv1cm6aainnmvolgo89i at
> nospam at (Pat Knight) wrote:
> >Sadly, it now means there's *more than one way to do it* (x += 1 and
> >x = x +1). I understand the two might have slightly different semantics
> >some cases?
> Which makes only one way to do each. Not so bad ;-)

Indeed, perfect.  If you want to make "sure" that, whatever object
x is now referring to, that object is not modified (so other
references, if any, are not affected), then use the form:
    x = x+1

(I use quotes around "sure" because object implementers ARE allowed
to do funny things -- such as modify an object on whatever excuse --
but that would surely be a violation of 'principle of least surprise').

If you do not care about what happens to other references (if any),
then use the form:
    x += 1
which can be either equivalent to the above, or, more efficient, if
x is currently bound to a mutable object.  I think this is the normal
case, but it's nice to have both options available.


More information about the Python-list mailing list