__init__ explanation please

Hrvoje Niksic hniksic at xemacs.org
Mon Jan 14 19:47:41 CET 2008

"Reedick, Andrew" <jr9445 at att.com> writes:

>> Only if by "construct" you mean "allocate".  __init__ starts out
>> with an empty object and brings it to a valid state, therefore
>> "constructing" the object you end up with.  That operation is
>> exactly what other languages call a constructor.
> Nah.  Most other languages combine the constructor and an init
> function.

Maybe so, but the standard term for what Python calls __init__ is
still "constructor".

> Also, how can a constructor require 'self' as an argument...?
> __init__(self, ...)

Think of it as the equivalent of Java's and C++'s "this", except it's
explicit in the argument list.  "Explicit is better than implicit" and
all that.  :-)

More information about the Python-list mailing list