Can Python function return multiple data?

random832 at fastmail.us random832 at fastmail.us
Thu Jun 4 13:30:52 EDT 2015


On Thu, Jun 4, 2015, at 13:11, Steven D'Aprano wrote:
> You need at least one more test to prove pass by value: you need to
> demonstrate that the value bound to y is copied when passed to the
> function. E.g. pass a mutable value (say, a list) and mutate it inside
> the
> function. If the list in the outer scope is *not* mutated, then and only
> then can you say it is pass by value.

That's not true at all. Being able to mutate the object doesn't make it
not-pass-by-value any more than being able to use an int argument as an
index to mutate a global array makes the int not-pass-by-value.

a = [0]*16

def f(x, i):
    x[i] = 3

f(a, 0)

If x is not pass-by-value, then clearly i is also not pass-by-value,
despite integers being immutable. Being able to use an argument to cause
a side effect does not mean the argument has not been passed by value.

a hasn't changed, 0 hasn't changed, the only thing that has changed is
the list object, which is *not the same thing as a*.



More information about the Python-list mailing list