Default parameters

Rainer Deyke rainerd at eldwood.com
Sat Dec 20 01:03:06 EST 2003


Carl Banks wrote:
> Well, personally, I don't see much use for non-constant default
> arguments, as we have them now, wheras they would be useful if you
> could get a fresh copy.

I disagree completely.  If a function modifies one of its arguments, this is
a fundamental property of that function.  If using a default value for that
argument causes the function to swallow the changes it performs, the
function no longer has consistent behavior.

On the other hand, the following function has consistent, if silly,
behavior:


default_list = []

def append_5_to_a_list(which_list = default_list):
  which_list.append(5)


-- 
Rainer Deyke - rainerd at eldwood.com - http://eldwood.com






More information about the Python-list mailing list