Re: Newbie question - default values of a function

2004-12-23 Thread Steve Holden
Bulba! wrote: Thanks everyone (esp. Fredrik, http://www.effbot.org/zone/index.htm contains lotsa goodies by him I intend to study), I'm going offline to reboot my brain. ;-) Bulba, with reference to your "don't laugh" comment, I'd just like to say that for a newbie your questions do have a habi

Re: Newbie question - default values of a function

2004-12-22 Thread Bulba!
Thanks everyone (esp. Fredrik, http://www.effbot.org/zone/index.htm contains lotsa goodies by him I intend to study), I'm going offline to reboot my brain. ;-) -- It's a man's life in a Python Programming Association. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question - default values of a function

2004-12-22 Thread Fredrik Lundh
"Bulba!" wrote: > Surely the variable i is a mutable object? nope. > OK, again: > def t(a,i=[0]): > ... i[0]=i[0]+1 > ... return (a, i) > ... t(1) > (1, [1]) t(3) > (3, [2]) t(5) > (5, [3]) > > Yes, it works with the list. But why sharing value between calls > pertains some m

Re: Newbie question - default values of a function

2004-12-22 Thread Bulba!
On Wed, 22 Dec 2004 22:29:44 GMT, "Matt Gerrans" <[EMAIL PROTECTED]> wrote: >Actually i was not mutable. Try this: >i = 1 >id(i) >i += 1 >id(i) Looks like I will have to read the Language Reference anyway. :-( >Because you are assigning the local reference variable L to a new list, >instead

Re: Newbie question - default values of a function

2004-12-22 Thread Matt Gerrans
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 diffe

Re: Newbie question - default values of a function

2004-12-22 Thread Dennis Benzinger
Bulba! wrote: > [...] > But why the following happens? > > def j(a,i=0): > > ... i=i+1 > ... return (a, i) > ... > j(2) > > (2, 1) > j(3) > > (3, 1) > j(5) > > (5, 1) > > > From Language Reference: > > http://www.python.org/doc/2.3.4/ref/function.html > > "Default

Newbie question - default values of a function

2004-12-22 Thread Bulba!
OK. Don't laugh. There's this example from tutorial, showing how default value is computed once when defining function and shared between function calls: --- def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) This will print [1] [1, 2] [1, 2, 3] --- (Pyth