Mutable parameters to functions

Alwyn Schoeman alwyns at prism.co.za
Wed Dec 15 07:38:31 EST 1999


Hi,

I've been working through Mark and David's book Learning Python.

On page 105 there is an example that states that when you change
a argument that is mutable in place (thew!) then you also change
the value of the variable in the callers namespace.

Ok, now on page 107 there is an example on returning multiple
values.  The code is as follows:
def multiple(x,y):
    x = 2
    y = [3,4]
    return x, y

X = 1
L = [1, 2]
X, L = multiple (X, L)
X, L

result is then (2, [3, 4])
Now, the question is whether the statement y = [3, 4] constitutes
an inplace change of the global variable L?
would  X = multiple(X,L) yield the same results?

Thank you

--
~~~~~~~~~~~~~~
Alwyn Schoeman
Systems Engineer
Prism Secure Solutions







More information about the Python-list mailing list