Can Python function return multiple data?

Steven D'Aprano steve at pearwood.info
Thu Jun 4 09:47:36 EDT 2015


On Thu, 4 Jun 2015 08:28 am, sohcahtoa82 at gmail.com wrote:

> On Wednesday, June 3, 2015 at 2:57:00 PM UTC-7, Mark Lawrence wrote:
[...]
>> Now does Python pass by value or by reference?  Happily sits back and
>> waits for 10**6 emails to arrive as this is discussed for the 10**6th
>> time.
 
> People actually argue that Python passes by value?  This is easily proven
> wrong by passing a mutable object to a function and changing it within the
> function.


You would be surprised how many people don't allow either facts or common
sense to get in the way of their preconceived notions.

The Python community has more or less reached consensus that Python uses the
calling convention usually called "pass by object" or "call by sharing"
(although it has a few other names), especially since the Python docs uses
the term.

But you still find a few people here and there who have been exposed to Java
foolishness, and will argue that Python is "pass by value, where the value
is an implementation dependent reference to the thing that you thought was
the value".

In other words, according to this Java philosophy, following `x = 23`, the
value of x is not 23 like any sane person would expect, but some invisible
and unknown, and unknowable, reference to 23.

As Fredrik Lundh (the Effbot) wrote:

    well, I guess you can, in theory, value an artificial number 
    assigned to an object as much as the object itself.

        "Joe, I think our son might be lost in the woods"
        "Don't worry, I have his social security number"

http://effbot.org/zone/call-by-object.htm


This may also be helpful:

http://import-that.dreamwidth.org/1130.html



-- 
Steven




More information about the Python-list mailing list