I have this code:
class Pere():
def __init__(self, nom):
self.nom = nom
def yeux(self):
print 'les yeux bleus'
class Mere():
def __init__(self, nom):
self.nom = nom
def taille(self):
print 'je suis longue!'
class Enfant(Pere, Mere):
pass
And in some tutorials speaking about inheritance
, they use ParentClass.__init__(self, *args)
for the child constructor.
Here is the example where it is used:
class Person(object):
def __init__(self, nom, age):
self.name = nom
self.age = age
def __str__(self):
return 'je suis {0}, et j\'ai {1} ans'.format(self.name, self.age)
class Militaire(Person):
def __init__(self, nom, age, grade):
Person.__init__(self, nom, age)
self.grade = grade
def __str__(self):
return Person.__str__(self) + ' et je suis un {0}'.format(self.grade)
When to use it?
In multiple inheritance, we dont need it (write it twice for example if it exists)?