Pass by reference ?

Jacek Generowicz jmg at ecs.soton.ac.uk
Mon Apr 3 11:30:49 CEST 2000


Hi,

I'm just trying to familiarize myself with Python.
In Magnus Lie Hatland's Instant Python, he
mentions that `all parameters in Python are passed
by reference'.

So I tried the following code:

#!/usr/bin/python

def increment(x):
    x = x + 1
    return x

a = 0
print a
print increment(a)
print a
====================

output:

0
1
0

Given my understanding of passing by reference,
the last number should be 1.

What am I missing ?

Thanks,

Jacek





More information about the Python-list mailing list