B
B
Ben_r0072020-05-04 21:19:13
Python
Ben_r007, 2020-05-04 21:19:13

Where to use super?

Hello.
I know and understand what MRO is.
But I don't understand what super is.
I understand that super is needed if we want to call the parent constructor in the constructor.
But after all, not only the constructor can be called through super ...
From this question.
Why is super needed, and where to use it?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-05-04
@trapwalker

With super(), you can call any parent methods, not just the constructor.
By the way, __init__ is not a constructor, strictly speaking. It does not create an instance. An instance is created in __new__, which is, in fact, a constructor. And __init__ is initialization. Although, in general, no one cares and everyone calls him a designer too. For simplicity.
Python has multiple inheritance. super creates a proxy object with an interface to the ancestors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question