Can Python function return multiple data?

Marko Rauhamaa marko at pacujo.net
Thu Jun 4 11:04:56 EDT 2015


Grant Edwards <invalid at invalid.invalid>:

>> 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.
>
> Somebody else might just as honestly say that it's pass by reference:

Yes, but that would be a shift from the 1970's notion:

   In pass-by-value, the actual parameter is evaluated. The value of the
   actual parameter is then stored in a new location allocated for the
   function parameter.

   [...]

   In pass-by-reference, the actual parameter must have an L-value. The
   L-value of the actual parameter is then bound to the formal
   parameter.

   [...]

    * A parameter in Pascal is normally passed by value. It is passed by
      reference, however, if the keyword var appears before the
      declaration of the formal parameter.

      procedure proc(in: Integer; var out: Real);

    * The only parameter-passing method in C is call-by-value; however,
      the effect of call-by-reference can be achieved using pointers. In
      C++ true call-by-reference is available using reference parameters.

   <URL: http://www.cl.cam.ac.uk/teaching/0910/ConceptsPL/Algol-Pasca
   l.pdf>

Pass by reference could easily be added to Python, too, if that were
deemed useful.


Marko



More information about the Python-list mailing list