I think you have something wrong there. The correct code for parent / derived class would be
class A:
def __init__(self, number):
self.number = number
class B(A):
def __init__(self, number):
super().__init__(0) # Initialize parent class.
self.number = number
# Instantiate a B object
test = B(7)
# Print the property
print(test.number)
That will always produce '7' in the screen. Now both A and B __init__
methods refer to the same 'number' property of the object, so, it does not make much sense both classes setting the same property upon initialization. If you change B's __init__
method for:
class B(A):
def __init__(self, number):
self.number = number
super().__init__(0) # Initialize parent class.
Then print(test.number)
would always print '0' instead of anything you passed on creation because you are overwriting the property.
The typical code would rather be:
class A:
def __init__(self, number):
self.number = number
class B(A):
def __init__(self, number):
super().__init__(number)
This way the derived class initializes the parent in a meaningful way.