Postfix/Prefix Operators (++,--)
Peter Hansen
peter at engcorp.com
Fri Jun 6 11:35:49 EDT 2003
Joshua Marshall wrote:
>
> Peter Hansen <peter at engcorp.com> wrote:
> ...
>
> > Secondly, in Python assignment actually *rebinds* a name to a new
> > object, so i = i + 1 creates a new object that is one greater than
> > the old, and rebinds the name "i" to it (like a pointer). The old
> > value, if there are no more references to it, is destroyed.
>
> > This, combined with the fact that these integer objects are actually
> > *immutable* (they cannot be changed!) pretty much prevents any
> > possibility of those operators working the way you'd expected.
>
> ++/-- can be added to Python, and could act in a way that wouldn't
> surprise C or Java programmers. There really isn't any conceptual
> difference between references to immutabe ints and C/Java primitive
> ints.
How would the error generated when the C or Java programmer wrote
the following code not surprise him or her?
c = 1
a = c++
-Peter
More information about the Python-list
mailing list