can someone explain?
Andrew Bennetts
andrew-pythonlist at puzzling.org
Tue Feb 18 02:04:54 EST 2003
On Tue, Feb 18, 2003 at 01:19:33AM -0500, Mongryong wrote:
> On Mon, 2003-02-17 at 11:35, Pablo wrote:
> > def increase(val):
> > val +=1
> As other's have explained, simple types like 'ints' are
> passed-by-value. You'll need a wrapper class for pass as reference.
Actually, everything -- including ints -- is passed by reference.
The reason it seems that things like ints are passed-by-value, is because
they are immutable. Thus, operations like "x + y" and "val += 1" return a
new int, rather than changing the existing one in place.
Strings, all the numeric types, and tuples are immutable.
-Andrew.
More information about the Python-list
mailing list