What is a function parameter =[] for?

Steven D'Aprano steve at pearwood.info
Sun Nov 22 07:01:59 EST 2015


On Fri, 20 Nov 2015 11:39 pm, BartC wrote:

> What's bothering me is:
> 
> * The large amount of mumbo-jumbo used to describe what's going on

Just because you don't know the terminology doesn't make it mumbo-jumbo. 

That's a particularly unfair and unjustified response to make when multiple
people have spent a lot of their own time, gratis, to explain what is going
on. If you are willing, you can learn a lot here, one of the few places
left where education is still free.


> * The insistence (I think largely from Steven) that the way this feature
> works is good rather than bad

It is good. It's just not good for *everything*.


> * The refusal to acknowledge that the def fn(a=[]) syntax is misleading.
> (What value will a have when you call fn()? The true answer is that you
> can't tell.)

I'm not really sure that anyone has disputed that specific point.

I'd say that the value of the default `a` could change, which is no
different from most other uses of mutable values. This is why some people
insist that mutable values are a mistake, and programming should only
involve immutable, fixed, values.


> * The persistent nonsense that somehow [] is mutable (what happens is
> that [] is assigned to a variable, and /that/ is mutable)

No, objects are mutable, or immutable, as the case may be



-- 
Steven




More information about the Python-list mailing list