functions, list, default parameters

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Oct 29 04:24:23 EDT 2010


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.

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

-- 
Greg



More information about the Python-list mailing list