28 What is Super Function or Method in Python programming?

Veröffentlicht am: 13 Dezember 2023
auf dem Kanal: Free Tutorial TV
8
1

So to start with I have two classes here.

One is the parent class and other is the child class . and here parent class acts like a superclass and

the child class acts like a subclass. which is inheriting from the parent class or both.

These classes have this init function and you already know what does this function do.

It is the first function which is called when an instance of a class is created.

And here I am just creating the object from the child class.

Now what do you think will happen when this constructor will be called or this constructor will be called.

because we are inheriting from the parent class into the child class.

So let's find out.

I'm going to run this code and it brings child init.

That means this statement under the child class init method is executed .
and the parent method is not executed.

Now in some cases you might want to pass some parameter into your superclass for example I'm

just going to give this example let's say I want to pass argument call the name here. and then I will

just print the value of name.

How can I call this init function using this child class instance.

So it turns out that that is a function called super in Python that allows us to refer to the superclass

implicitly.

Now this super function is a built in function which returns a proxy object that allows you to refer

to your superclass.

So let's try to use this super function.

So you just use the keyword super and then give these parenthesis because this is a function.

And then this super function will return the proxy object of the superclass.

That means I can use this dot operator to call init method from the superclass. So this notation means

Super dot init.

It means we are calling the init method from the parent class. and that means we can parse the name

from here.

So let's just parse this now, I'm going to just write Max here and now I'm going to run this code.

And now you will see that child in it is printed using this statement.

First of all and then using the super function that it method of parent last is called. and then

this name is parse here. and it prints parent init and the name whatever name we have provided here.

So this superfunction allows us to refer to the superclass.

Now let me show you one more thing which is called the method of resolution order . and you can find this

method resolution order by using your last name so a child's last name dot underscore underscore M R O.

Underscore Underscore M R O underscore underscore and this statement I'm going to use inside the print

function so you can see the result what it return so I'm going to run the code now and you can see it

or.

This kind of order.


**************************************************************************
please like and follow us in Facebook and Instagram.
facebook:   / technologytv  


Instagram:   / heikhamsingh  


Twitter:   / hanandkumarsing  


Auf dieser Seite können Sie das Online-Video 28 What is Super Function or Method in Python programming? mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Free Tutorial TV 13 Dezember 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 8 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!