Actually i was not mutable.   Try this:

i = 1
id(i)
i += 1
id(i)

Change both of your sample functions to also print the id of the default 
variable and that might shed a little more light on the matter.

"i = i + 1" is only changing the local reference called i to refer to an 
instance of a different integer object.    If you change the original 
function to something similar, it will behave similarly:

def f( a, L=[]):
   L = L + [a]
   return L

Because you are assigning the local reference variable L to a new list, 
instead of modifying that original default list that was created.

Is that more clear, or is it now more unclear?   ;) 


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to