What is a function parameter =[] for?

Ned Batchelder ned at nedbatchelder.com
Tue Nov 24 09:50:33 EST 2015


On Tuesday, November 24, 2015 at 9:34:36 AM UTC-5, Antoon Pardon wrote:
> Op 20-11-15 om 13:12 schreef Ned Batchelder:
> > 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.
> 
> May be you should get this message through to the python tribe, so that
> they stop reacting as a stung horse each time someone finds something
> bizarre with the language.

I agree with you: Python experts shouldn't be surprised when people are
surprised by this behavior.

> 
> > 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?
> 
> Maybe just have us recognize that some aspects of python indeed are bizarre.
> That there is nothing wrong with him thinking so. After that he will have
> to make up his mind whether this bizarre aspect is to big a hurdle for
> using the language or not, because it seems unlikely to change.

I also agree with you: there is nothing wrong with people thinking parts of
Python are bizarre.  What we ask is that people then try to understand
how Python works.  If people say, "This surprised me, Python is stupid!"
and then leave it there, the conversation is bound to go poorly.

Every language works differently, and every language has things that will
surprise new learners.

--Ned.



More information about the Python-list mailing list