-
Case1:
Define Base.init(self)
class Base(object):
def __init__(self):
self.anattribute = 23
class Derived(Base):
def __init__(self):
Base.__init__(self)
self.anotherattribute = 45
# Expect 23 here as an output
Derived().anattribute
# 23
- Case2: Don't define Base.init(self)
class Base(object):
def __init__(self):
self.anattribute = 23
class Derived(Base):
def __init__(self):
self.anotherattribute = 45
# Expect an exception here
Derived().anattribute
-
Case3:
Don't define Derived.init(self)
class Base(object):
def __init__(self):
self.anattribute = 23
class Derived(Base):
pass
# Didn't define __init__ so automatically Base.__init__.py will be called
Derived().anattribute