In your example, there is no difference, it is the same thing. The difference only appears when you use diamond-shaped multiple inheritance:
A
/ \
B C
\ /
D
class A:
def teste(self):
print("teste em A")
class B(A):
def teste(self):
print("teste em B")
super().teste() # Equivalente a A.teste(self)
class C(A):
def teste(self):
print("teste em C")
super().teste() # Equivalente a A.teste(self)
class D(B, C):
def teste(self):
print("teste em D")
super().teste() # ?????????????????
d = D()
d.teste()
As the class D inherits so much of B how much of C, within the method D.teste you would have to call both methods C.teste(self) and B.teste(self), however, as each of these calls A.teste, the result without using the super()would it be that A.teste would be called twice.
The solution is the super() - it serves for each ancestral method to be called only once, in order of definition.
The exit will be:
teste em D
teste em B
teste em C
teste em A
Thank you! I understood the purpose of using the
super(), but what I’d really like to know is the difference between the two ways of using that I mentioned in the question.– Thiago Krempser
The answer, although correct and contain information on the
super(), does not correspond to the question asked.– nosklo