Name
__init__
Synopsis
__init__(self[,args
...])
When a call
C
(
[args...]
)
creates instance x
of class
C
Python calls
x
.__init__(
[args...]
)
to let x
initialize itself. If __init__
is absent, you must call class
C
without arguments,
C
( )
, and
x
has no instance-specific attributes upon
creation (note that __init__
is never absent for
a new-style class, since such a class inherits __init__
from object
unless it redefines it).
__init__
must return None
.
Python performs no implicit call to __init__
methods of class C
’s
superclasses. C
.__init__
must explicitly perform any needed initialization. For
example, when class C
has a base class
B
to initialize without arguments, the
code in C
.__init__
must explicitly call B
.__init__(self)
(or better, for new-style classes, call
super(
C
,
self).__init__( )
).
Get Python in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.