Re: [Tutor] newbie question about default arguments

2006-03-29 Thread Kent Johnson
Josh Adams wrote: > Thanks for your help. That makes a lot more sense. > > Not to ask too many stupid questions, but why does the L2 assignment in the > if-block create a new L variable? Shouldn't the scope from the function > definition dominate the inner scope of the if-block? It doesn't cr

Re: [Tutor] newbie question about default arguments

2006-03-29 Thread Josh Adams
Thanks for your help. That makes a lot more sense. Not to ask too many stupid questions, but why does the L2 assignment in the if-block create a new L variable? Shouldn't the scope from the function definition dominate the inner scope of the if-block? Thanks, Josh > Josh, > > If you print t

Re: [Tutor] newbie question about default arguments

2006-03-29 Thread Pujo Aji
Hello Josh,you wrote a different problem. The tutorial should be like this: Important warning: The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes. For example, the following function accum

[Tutor] newbie question about default arguments

2006-03-29 Thread Josh Adams
Hi all, I was going through the tutorial at http://docs.python.org/tut/node6.html when I came to the bit about default arguments with this code: def f(a, L=[]): L.append(a) return L print f(1) print f(2) print f(3) returns: [1] [1, 2] [1, 2, 3] >From the postings here, I think I underst