Can Python function return multiple data?

Steven D'Aprano steve at pearwood.info
Thu Jun 4 22:37:28 EDT 2015


On Fri, 5 Jun 2015 08:59 am, random832 at fastmail.us wrote:

> On Thu, Jun 4, 2015, at 18:16, Steven D'Aprano wrote:
>> Remember, you've tried to claim that it is not invisible or unknown, so
>> you
>> must be able to see and know that value. So what is the value?
> 
> It doesn't have to have a string representation to exist. But if you
> really want one?
> 
>>>> object.__repr__(23)
> '<int object at 0x10024af00>'

That's not a reference to the value. That's a string that describes the
object. If it returned

"twenty-three"

would you claim that the string "twenty three" is the value of x?

I think there is a simple, obvious, common-sense answer here:

* given `x = 23`, the value of x is 23;

* given `x = [1, 2]`, the value of x is the given list [1, 2];

* given `x = "Hello World", the value of x is the string "Hello World";

* given `x = object()`, the value of x is the given instance of type object.

That's so simple and obviously correct. Compare to:

* given `x = 23`, the value of x is not actually 23, but some invisible
reference to 23;

* given `x = [1, 2]`, the value of x is not actually [1, 2], but some
invisible reference to [1, 2]; 

etc. I'm sure you can extrapolate to the other examples.

The *only* reason for making this claim is to rationalise the belief that
passing x to a function is pass by value. Since the list [1, 2] is
obviously not copied, it becomes necessary to find something, anything,
which *is* copied, and identify that as "the value of x". Is there any
other context where you would want to say that the value of x isn't [1, 2]?


-- 
Steven




More information about the Python-list mailing list