A question on modification of a list via a function invocation

Ben Finney ben+python at benfinney.id.au
Wed Aug 16 20:56:51 EDT 2017


Steve D'Aprano <steve+python at pearwood.info> writes:

> On Thu, 17 Aug 2017 08:29 am, Mok-Kong Shen wrote:
>
> > I have earlier learned some other (older) programming languages. For
> > these the formal parameters are either "by reference" or "by value".
>
> By reference and by value are not the only two conventions.
>
> Perhaps if you go back to the 1950s you might be able to argue that
> "reference" and "value" are the only two conventions, but alternatives
> have existed for many decades, since *at least* 1960 when Algol
> introduced "call by name".

Indeed. I have had a lot of success helping people, who come to Python
with the baggage of that false dichotomy, by using Fredrik Lundh's term
“call by object” to describe the Python argument-pass semantics.

    Python’s model is neither “call by value” nor “call by reference”
    (because any attempt to use those terms for Python requires you to
    use non-standard definitions of the words “-value” and
    “-reference”). The most accurate description is CLU’s “call by
    object” or “call by sharing“. Or, if you prefer, “call by object
    reference“.

    <URL:http://www.effbot.org/zone/call-by-object.htm>

> This may help:
>
> http://import-that.dreamwidth.org/1130.html

That's a good one too, thank you for writing it. I just wish Dreamwidth
would present a URL with a slug derived from the article title, so that
it was easier to search the URLs in my history :-)

-- 
 \       “Some people have a problem, and they think “I know, I'll use |
  `\     Perl!”. Now they have some number of problems but they're not |
_o__)     sure whether it's a string or an integer.” —Benno Rice, 2011 |
Ben Finney




More information about the Python-list mailing list