I'm getting some inconsistencies with how this work. In the tutorial, the example clearly demonstrates that the list is passed by reference, so any changes to the list within the function is reflected in the original value after the function ends.
def fun1(a,L=[]):
L.append(a)
return L
print fun1(1)
print fun1(2)
print fun1(3)
[1]
[1, 2]
[1, 2, 3]
If I try THIS example, however, why does b not change (i.e. if b is stored as "2", then it should return 3)?
def g(a, b=1):
b=a+b
return b
>>> g(1)
2
>>> g(1)
2
I'm going to guess that it's because the statement b = a+b assigns b to a new b that is only accessible within the function environment, but isn't this inconsistent with how the first example works (in which it's obvious that the variable L was defined BEFORE the function starts, and also can be altered within the function itself).