[Tutor] Python Function Doubt

Alan Gauld alan.gauld at btinternet.com
Tue May 26 19:26:36 CEST 2009

"nikhil" <nik.mis at 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 


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list