"nikhil" <nik....@gmail.com> wrote

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

In Python the parameters are not objects but names.
names are used to reference objects. If there is no default value then there is no object to store.

So to answer your question, yes, it only affects parameters with default values but no, new objects are not created for the other parameters on each call, rather the other arguments are bound to the arguments passed by the functions user.

This leads to the sometimes confusing situation with mutable types that Dave referred to. If the function changes a parameter value and it is mutable then the original object is changed. If it is immutable a new object is assigned to the parameters name.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to