What is a function parameter =[] for?

Gregory Ewing greg.ewing at canterbury.ac.nz
Sun Nov 22 18:30:02 EST 2015


BartC wrote:
> What's bothering me is:
> 
> ...
> 
> * The insistence (I think largely from Steven) that the way this feature 
> works is good rather than bad

Here's one reason to prefer the way it currently works:

It's rare to want a mutable default value. The vast
majority of default values are simple things such as
None, 0 or "". Evaluating the default expression on
every call in those cases would just be useless
overhead. So Python optimises for the most common
case. When you need a mutable default, there is a
straightforward way to get it.

-- 
Greg



More information about the Python-list mailing list