[Tutor] __init__, default values and dict's

Kent Johnson kent37 at tds.net
Thu Aug 14 12:37:21 CEST 2008


On Thu, Aug 14, 2008 at 6:05 AM, Bart Cramer <bart.cramer at gmail.com> wrote:
> Dear tutors,
>
> I have the following code snippet:
>
> class N (object) :
>
>        def __init__ (self, d={}) :
>                self.d = d
>
> I assumed that on each call of the __init__ without a dictionary
> provided, a new dictionary is created.

http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm

Kent


More information about the Tutor mailing list