integers

Alan Daniels daniels at mindspring.com
Tue Jun 5 22:45:00 EDT 2001


On Tue, 5 Jun 2001 13:55:57 -0700, Humanity let out a collective sigh
of relief when Jonathan Gardner <gardner at cardomain.com> finally typed:

>What is the reason that python doesn't have increment or decrement 
>operators?

Integers in python are immutable (same as strings, floats, tuples,
etc). That is, they're objects that cannot have their contents changed
once they are created. In other words, having a ++ or -- operator
doesn't make any sense since integers can't be changed in place. When
you say "x = x + 1", you're really creating a new integer object and
assigning over the old one.

I believe the new "x += 1" syntax is just synactic sugar which serves
as shorthand for "x = x + 1", although I'd have to delve through the
interpreter source code to be 100% sure.

(This question comes up often enough... I wonder if it should be in
the FAQ?)
==============================
Alan Daniels
daniels at alandaniels dot com



More information about the Python-list mailing list