Huh? func_defaults, default values in function calls

Jeff Senn senn at
Wed Apr 12 11:14:41 EDT 2000

"Fredrik Lundh" <effbot at> writes:
> Mark Hathaway <hathawa2 at> wrote:
> > >> As a result, if you set a mutable object (list, dictionary, etc) as a
> > >> default, it'll be set when the function is defined and then if the
> > >> function changes it, it'll stay changed for subsequent invokations.
> > >> The function effectively has a "side-effect", of modifying it's own
> > >> default!
> >
> > This way you'll never really know what the default is going to be.
> uhuh?  so you mean evaluating the default value every time the
> function is called would automatically make it easier to know what
> the default is going to be?  what about non-trivial default values?
> what about scoping?  what about side effects? what about per-
> formance?  etc.
> > Ha ha ha ha. that's pathetic.
> really?  I'm pretty sure Guido designed things this way on purpose,

Yep. Note (also) that you can use a non-mutable value as the
default if you don't want this behavior. Oh....I mean... if there *are*
such in things in the language...  maybe I should go wade into the
do-we-really-need-immutable-aggregates-in-Python argument....

...maybe not...;-) 


More information about the Python-list mailing list