Answer the question
In order to leave comments, you need to log in
What happens when super() is called on a child?
Hello.
class Person():
def __init__(self, name):
self.name = name
class MDPerson(Person):
def __init__(self, name):
self.name = name
super.__init__(name)
mdperson = MDPerson('Fudd')
Answer the question
In order to leave comments, you need to log in
Person will create a name field, because the ancestor did not have such a field.
MDPerson will use the name field that it inherited.
If you call super, then the Person method will be called, which will change the same variable.
An object of the MDPerson class is also an object of the Person class and other ancestors, since MDPerson inherited all abilities from Person, so it can be used in the same place as objects of the Person class.
print(isinstance(mdperson, Person), isinstance(mdperson, MDPerson) )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question