{"id":3914,"date":"2022-12-05T07:59:58","date_gmt":"2022-12-05T07:59:58","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3914"},"modified":"2022-12-05T08:00:00","modified_gmt":"2022-12-05T08:00:00","slug":"call-superclass-method-python","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/call-superclass-method-python\/","title":{"rendered":"Call Superclass Method Python"},"content":{"rendered":"<p style=\"text-align: center;\">Call Superclass Method Python<\/p>\n<p>Well, now the thing is that when we have our own implementation for the eat method in the Lion class, it would call that eat method only, whenever called. But what if we need to call the eat method from the superclass, which is the Animal class? In short, we are going to have a look at what to do, if we need to call the method from the superclass, instead of the one, that is overriding.<\/p>\n<p>The thing is that we are calling the Animal class a superclass. So here, we are going to use the super function, which would allow us to call the method from the superclass. Let\u2019s have an example, which demonstrates the use of a super function to call the method from the superclass.<\/p>\n<h2 style=\"text-align: center;\">Call Superclass Method Python<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3915 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/11\/WHAT-IF-YOU-WANT-TO-CALL-THE-SUPER-CLASS-METHOD.jpg\" alt=\"\" width=\"646\" height=\"195\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/11\/WHAT-IF-YOU-WANT-TO-CALL-THE-SUPER-CLASS-METHOD.jpg 646w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/11\/WHAT-IF-YOU-WANT-TO-CALL-THE-SUPER-CLASS-METHOD-300x91.jpg 300w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/p>\n<p>As you can see, we have the doSomething method with the child class as well, but inside that, we are calling the doSomething method from the superclass. So, using the super function, we can simply call the superclass method.<\/p>\n<p>Alternatively, we can do the same thing using the name of the class, which, we can call the doSomething method in this case.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3916 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/11\/WHAT-IF-YOU-WANT-TO-CALL-THE-SUPER-CLASS-METHOD-1.jpg\" alt=\"\" width=\"650\" height=\"213\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/11\/WHAT-IF-YOU-WANT-TO-CALL-THE-SUPER-CLASS-METHOD-1.jpg 650w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/11\/WHAT-IF-YOU-WANT-TO-CALL-THE-SUPER-CLASS-METHOD-1-300x98.jpg 300w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<p>As you can see, using the class name, we have called the method doSomething. In this case, as well, one argument is to be passed to the method. In this way, we can simply call the methods from the superclass, instead of calling the methods of the child class.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Call Superclass Method Python Well, now the thing is that when we have our own implementation for the eat method in the Lion class, it would call that eat method only, whenever called. But what if we need to call the eat method from the superclass, which is the Animal class? In short, we are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3914","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3914","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3914"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3914\/revisions"}],"predecessor-version":[{"id":4246,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3914\/revisions\/4246"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3914"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3914"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3914"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}