Can Python function return multiple data?

Grant Edwards invalid at invalid.invalid
Thu Jun 4 22:02:09 EDT 2015


On 2015-06-04, Steven D'Aprano <steve at pearwood.info> wrote:
> On Fri, 5 Jun 2015 04:38 am, Grant Edwards wrote:
>
>>>> But, discussing pass-by-this vs. pass-by-that without also discussing
>>>> the semantics of the assignment operator is rather pointless.
>>>
>>> No, that's a red-herring.
>> 
>> I don't think so. ??The reason that many people seem to confused
>> about Python's argument passing is that they don't understand what
>> assignment does.
>
> I don't see the connection, but do explain, I'm interested.

To many people the difference between pass-by-value and
pass-by-reference is what the effects are of assigning to the formal
parameter from within the function.  Using the model of "assignment"
they're used to using from FORTAN/C/C++ Python appears to behave
weirdly and inconsistently.

But, it's not really because the parameter passing mechnism is
something novel (it's not). It's because of what assignment does.
Python's parameter passing is quite simple: it's exactly the same as
an assignment: it binds a name within the funciton's namespacepace to
an object.  If you don't first understand that's what an assignment
does, then trying to explain the parameter passing using phrases
spelled 'pass-by-<whatever>' isn't going to help.

At least that's how it works in my head.  First, you have to
understand assignment.  Then you can understand what Python parameter
passing does.

Or to be a bit obtuse: Python parameters are passed by value, but all
values are references.

[I once had a CS prof who didn't know there was anything other than
pass-by-reference, but that's another story.]

--
Grant





More information about the Python-list mailing list