A question on modification of a list via a function invocation

Chris Angelico rosuav at gmail.com
Mon Sep 4 06:37:16 EDT 2017


On Mon, Sep 4, 2017 at 8:27 PM, Rustom Mody <rustompmody at gmail.com> wrote:
> That's fine as far as it goes
> But then you have people (Steven above) who feel that python passing has
> no exceptions (in parameter passing)
> Does a poor job AFAIAC of explaining the difference between foo and bar in foll
>
>>>> def foo(x): x += 2
>>>> def bar(x): x.append(2)
>>>> a=10
>>>> b=[10]
>>>> foo(a)
>>>> a
> 10
>>>> bar(b)
>>>> b
> [10, 2]
>>>>

It's all about assignment. In foo, you have an assignment statement;
in bar, you don't. The diagram showed the behaviour of assignment.

ChrisA



More information about the Python-list mailing list