functions, list, default parameters

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Fri Oct 29 04:41:33 EDT 2010


On Fri, 29 Oct 2010 21:24:23 +1300, Gregory Ewing wrote:

> John Nagle wrote:
>> On 10/21/2010 2:51 PM, Chris Rebert wrote:
> 
>>> This is a common newbie stumbling-block: Don't use lists (or anything
>>> mutable) as default argument values
> 
>>     That really should be an error.
> 
> No, it shouldn't. The criterion isn't whether the object is mutable, but
> whether you actually mutate it. If you treat it as read-only, there's no
> problem.

And how does Python know whether some arbitrary default object is mutable 
or not?

> Since not all Python data types have immutable variants, sometimes it's
> necessary to do this.


And sometimes you want the behaviour as it is.


-- 
Steven



More information about the Python-list mailing list