Can Python function return multiple data?

Grant Edwards invalid at invalid.invalid
Thu Jun 4 14:38:19 EDT 2015


On 2015-06-04, Steven D'Aprano <steve at pearwood.info> wrote:
> On Fri, 5 Jun 2015 12:37 am, Grant Edwards wrote:
>> On 2015-06-04, Marko Rauhamaa <marko at pacujo.net> wrote:
>
>>> Anyway, I would say Python definitely is in the classic pass-by-value
>>> camp. Here's a simple test:
>>>
>>>    def f(x):
>>>        x = 3
>>>
>>>    y = 1
>>>    f(y)
>>>    print(y)
>>>
>>> If it prints 1, it's pass by value. If it prints 3, it's pass by
>>> reference.
>
> Wrong.

>> Somebody else might just as honestly say that it's pass by reference:
>
> And they would be just as wrong.

Yep, that was my point.  They're both wrong and yet people can be just
as honest when they argue one or the other.

>> def f(x):
>>     x[2] = 2;
>> 
>> x = ['a','b','c']
>> f(x)
>> print(x)
>> 
>> If it prints ['a','b','c'], it's pass by value.  If it's pass by
>> reference, it prints ['a', 'b', 2].
>
> Wrong.

I know.

>> 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.

-- 
Grant Edwards               grant.b.edwards        Yow! Are we live or on
                                  at               tape?
                              gmail.com            



More information about the Python-list mailing list