Huh? func_defaults, default values in function calls

James "Wez" Weatherall jnw22 at cam.ac.uk
Tue Apr 11 10:39:08 EDT 2000


> > You won't get this behaviour with something like:
> >
> > def myfun(x, a = 5):
> >     a = x
> >
> > though, I don't think, because "5" isn't mutable.
>
> footnote: that has nothing to do with mutability.  in
> the following example, the list isn't modified either:

True.  A better example might be

def myfunc(x, a=[]):
    print x, a
    a.append(x)

def myfunc2(x, a=0):
    print x, a
    a = a + x

I suppose. :)

--
James "Wez" Weatherall






More information about the Python-list mailing list