A question on modification of a list via a function invocation

ROGER GRAYDON CHRISTMAN dvl at psu.edu
Mon Sep 4 08:01:59 EDT 2017


>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]
>>>> 
Or with just one function: >>> def baz(x,y):
 x += y 
>>> a = 10
>>> b = [10]
>>> baz(a,a)
>>> a
10
>>> baz(b,b)
>>> b[10, 10]







More information about the Python-list mailing list