[Tutor] Python Function Doubt

nikhil nik.mis at gmail.com
Tue May 26 16:12:34 CEST 2009


Thanks for reply.

I went through the link you provided. It was very helpful.

What I understood is this,

--> Objects are created for default argument types, inside the function
object. This
     happens only once when the function definition statement is executed.
These objects
     persist between function calls and not destroyed/garbage collected.

--> Since List is a mutable object, changes are made to the same object and
     it is visible between function calls.

Is my understanding correct ?

If so, I have a small doubt regarding function arguments.

Are objects for arguments, that persist between function calls, created
during function definition ONLY when they have default values ?


Objects are created for arguments irrespective of whether it has a default
value or not, but they are not persistent ( i.e a new object is created for
every function call ) ?


On Tue, May 26, 2009 at 6:29 PM, Christian Witts <cwitts at compuscan.co.za>wrote:

> It is a well known Python gotcha.  Take a read through the "Mutable
> defaults for function/method arguments" section of
> http://www.ferg.org/projects/python_gotchas.html#contents_item_6
> Hope that helps your understanding.
> --
> Kind Regards,
> Christian Witts
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090526/d9fb850f/attachment.htm>

More information about the Tutor mailing list