Something in the function tutorial confused me.
Steve Holden
steve at holdenweb.com
Mon Aug 6 19:01:12 EDT 2007
Marc 'BlackJack' Rintsch wrote:
> On Mon, 06 Aug 2007 10:51:20 -0700, Lee Fleming wrote:
>
>> why isn't the y in def f (x, y = []): something
>> garbage-collected?
>
> `y` is a name. Only objects are garbage collected. There is no `y` in
> that ``def`` in the sense that a local name `y` exists when the ``def`` is
> executed. The line just says there will be a local name `y` if
> the function `f()` is executed and that local name will be bound to the
> given object.
Unless the user provides a value for the argument in the call.
> Which happen to be a list. This list is referenced by the
> function object, so it won't get garbage collected, and it is bound to a
> local name `y` every time the function is called. It is always the
> very same list object. And if you mutate it, this will be visible to
> other calls to the function.
>
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
More information about the Python-list
mailing list