What is a function parameter =[] for?

Ned Batchelder ned at nedbatchelder.com
Fri Nov 20 07:12:47 EST 2015


On Friday, November 20, 2015 at 6:59:54 AM UTC-5, BartC wrote:
> On 20/11/2015 01:05, Steven D'Aprano wrote:
> > On Fri, 20 Nov 2015 04:30 am, BartC wrote:
> >
> >> On 19/11/2015 16:01, Steven D'Aprano wrote:
> > [...]
> >
> >> The whole concept of 'mutable' default is alien to me. A default is just
> >> a convenient device to avoid having to write:
> >>
> >>     fn(0) or fn("") or fn([])
> >
> > Says who?
> 
> People who want to avoid having to write:
> 
>       fn(0) or fn("") or fn([])

I think we all understand by now that you are unhappy with what happens
in Python with mutable defaults.  We get it.  You are not alone. Lots of
people are surprised by this.  But it is how Python works.

I'm not sure what your goal is at this point.  Are you:

  1) still unsure what the behavior is, or 
  2) trying to understand why it behaves that way, or
  3) hoping to change Python, or
  4) trying to convince us that your language is better, or
  5) something else?

--Ned.



More information about the Python-list mailing list