Can Python function return multiple data?

Marko Rauhamaa marko at pacujo.net
Fri Jun 5 05:27:55 EDT 2015


Alain Ketterlin <alain at universite-de-strasbourg.fr.invalid>:

> Grant Edwards <invalid at invalid.invalid> writes:
>
> [...]
>> Or to be a bit obtuse: Python parameters are passed by value, but all
>> values are references.
>
> Exactly, that's a perfect description. There's is no need for a new
> name. As a corollary, all names (including "variables" and object
> attributes) are references.

We are all confusing each other because of the word "reference" means so
many things.

In Grant's explanation, a "reference" is a pointer, the invisible gluons
that bind, say, a variable to an object.

In Alain's sentence a "reference" is a variable or any other "lvalue"
that can be bound to an object.

Thus, the statement

    a[3] = 4

contains the reference[Alain] "a[3]". After the statement is executed,
the reference[Alain] contains a reference[Grant] to an int object 4.

Now, is it useful to make the distinction and use the verb "contain?"

Yes, it is. Consider these statements:

    a[0] = 4
    a[1] = 4
    a[2] = a[1]

Now, "a[0]", "a[1]" and "a[2]" are three separate references[Alain].
However between the three, they contain a maximum of two distinct
references[Grant], which can be ascertained with an "is" test:

    a[2] is a[1]
    => True

So while the references[Grant] are identical, the references[Alain] are
not. If I'm not mistaken, Python has no means of comparing the
identities of references[Alain].


Marko



More information about the Python-list mailing list