Re: Something in the function tutorial confused me.

2007-08-06 Thread Lee Fleming
On Aug 6, 1:26 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Lee Fleming wrote: > > On Aug 6, 6:25 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: > > Because when the function is called, the line > > >> if y is None: y = [] > > > is exe

Re: Something in the function tutorial confused me.

2007-08-06 Thread Lee Fleming
Thanks for all the help, everyone. I guess I was confused with default arguments that were mutable and immutable. I will continue to look over these posts until I understand what is happening. I cannot believe the number of helpful responses I got! -- http://mail.python.org/mailman/listinfo/pyth

Re: Something in the function tutorial confused me.

2007-08-06 Thread Lee Fleming
On Aug 6, 12:30 pm, "Hamilton, William " <[EMAIL PROTECTED]> wrote: > When you call f(23), the variable y within it gets created and points at > None. When f(23) exits, the y that it created gets destroyed. (Well, > goes out of scope, but even if it's not garbage collected it won't ever > come ba

Re: Something in the function tutorial confused me.

2007-08-06 Thread Lee Fleming
On Aug 6, 6:25 am, Neil Cerutti <[EMAIL PROTECTED]> wrote: Because when the function is called, the line > if y is None: y = [] is executed, binding a brand new empty list to y. This "rebinding" happens every time the function is called, unless you provide an argument for y that is not Non

Something in the function tutorial confused me.

2007-08-05 Thread Lee Fleming
Hello, I have a simple question. Say you have the following function: def f(x, y = []): y.append(x) return y print f(23) # prints [23] print f(42) # prints [23, 42] As far as I understand, the default value y, an empty list, is created when the def statement evaluates. With this though