As the title suggests, I am struggling to understand the true purpose of the init constructor in Python and specifically when we create a class that inherits from another (parent). Having gone through "diveintopython", I am a bit confused as to what exactly happens when class B inherits from A.
In the following example (taken from here: What is the purpose of calling __init__ directly?)
class A:
def __init__(self, x):
self.x = x
class B(A):
def __init__(self, x, y):
A.__init__(self, x)
self.y = y
What exactly happens if we don't make the call to the parent init A.__init__(self, x)
?
Will attribute x still exist in class B?
Furthermore, shouldn't Class B(A)
already entail the call to parent init?
In other words are we allowed to skip the call, and if we do which would be the consequences?