Mutable parameters to functions

Alex Martelli Alex.Martelli at think3.com
Wed Dec 15 11:39:38 EST 1999


Alwyn writes:

> 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?
> 
No, it just rebinds the local variable y.

> would  X = multiple(X,L) yield the same results?
> 
Same results as X, L = multiple(X,L)?

No, it would place a tuple in X (rather than a
number) and leave L to the [1,2] list (rather
than bind it to [3,4]).


Alex





More information about the Python-list mailing list