Weird Python behaviour

Peter Otten __peter__ at
Tue Aug 10 14:18:02 CEST 2010

Jonas Nilsson wrote:

> Lets say that I want to feed an optional list to class constructor:
> class Family():
>     def __init__(self, fName, members = []):

> Why on earth is the output ['Bill', 'Joe']!? Is there a simple
> solution that separates f1 and f2 without forcing me to write code for
> the special case when you don't feed members to the __init__()-function?

Congrats; you just encountered a very popular new trap ;) The most recent 
explanation is only one day old:


More information about the Python-list mailing list