

{"id":6887,"date":"2018-02-01T06:57:40","date_gmt":"2018-02-01T01:27:40","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=6887"},"modified":"2026-04-28T11:18:21","modified_gmt":"2026-04-28T05:48:21","slug":"python-inheritance","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-inheritance\/","title":{"rendered":"Python Inheritance &#8211; Method Overloading &amp; Method Overriding"},"content":{"rendered":"<p>In this Python tutorial, we talk about Python inheritance and types of inheritance in Python with their syntax.<\/p>\n<p>Moreover, we will study Python super function, Python method overriding, and method overloading in Python.<\/p>\n<p>So, let&#8217;s start the Python Inheritance Tutorial.<\/p>\n<h3>What is Inheritance in Python?<\/h3>\n<p>Inheritance lets one class borrow from another. You write class Puppy(Dog): to say, \u201cPuppy is a kind of Dog.\u201d The new class gains all methods and data of Dog without rewriting them.<\/p>\n<p>It is a universal fact that every student is a person. This is in hindsight of non-human students if any. To depict this relationship, we take an illustration.<\/p>\n<div id=\"attachment_6889\" style=\"width: 233px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/generalization.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6889\" class=\"wp-image-6889 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/generalization.jpg\" alt=\"Python Inheritance\" width=\"223\" height=\"270\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/generalization.jpg 223w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/generalization-124x150.jpg 124w\" sizes=\"auto, (max-width: 223px) 100vw, 223px\" \/><\/a><p id=\"caption-attachment-6889\" class=\"wp-caption-text\">Python Inheritance &#8211; Illustration<\/p><\/div>\n<p>The relationship from person to a student is termed <span style=\"text-decoration: underline\">\u2018Specialization\u2019<\/span>. Conversely, every student is a person; this is called Generalization.<\/p>\n<p>In this representation, we use an arrow towards the base class as a UML (Unified Modeling Language) convention.<\/p>\n<p>Here, Person can be called any of the following:<\/p>\n<ul>\n<li>Super Class<\/li>\n<li>Parent Class<\/li>\n<li>Base Class<\/li>\n<\/ul>\n<p>Likewise, the student here is:<\/p>\n<ul>\n<li>Sub Class<\/li>\n<li>Child Class<\/li>\n<li>Derived Class<\/li>\n<\/ul>\n<h4>Features of inheritance in Python:<\/h4>\n<ul>\n<li><strong>Namespace behaviour:<\/strong> If a method is defined again with the same name, then it will replace the old one.<\/li>\n<li><strong>API Flexibility:<\/strong> It can create functions that can easily handle different types of tasks.<\/li>\n<\/ul>\n<h3>Python Inheritance Syntax<\/h3>\n<p>To make a class inherit from another, we apply the name of the base class in parentheses to the derived class\u2019s definition.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; class Person:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; class Student(Person):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; issubclass(Student,Person)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<p>Here, class Student inherits from class Person. Here, since we only want to focus on the Python syntax, we use the \u2018pass\u2019 statement in the bodies of the classes.<\/p>\n<p>Also, we use the function issubclass() to confirm that the student is a subclass of person.<\/p>\n<h3>Types of Inheritance in Python<\/h3>\n<p>There are five types of inheritance in Python, we observe.<\/p>\n<div id=\"attachment_6935\" style=\"width: 5010px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Types-of-Inheritance-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-6935\" class=\"wp-image-6935 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Types-of-Inheritance-01.jpg\" alt=\"Python Inheritance - Types\" width=\"5000\" height=\"2617\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Types-of-Inheritance-01.jpg 5000w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Types-of-Inheritance-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Types-of-Inheritance-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Types-of-Inheritance-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Types-of-Inheritance-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 5000px) 100vw, 5000px\" \/><\/a><p id=\"caption-attachment-6935\" class=\"wp-caption-text\">Types of Python Inheritance<\/p><\/div>\n<h4>1. Single Inheritance in Python<\/h4>\n<p>A single Python inheritance is when a single class inherits from another class.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; x=0\r\n&gt;&gt;&gt; class fruit:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def __init__(self):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 global x\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 x+=1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"I'm a fruit\")\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\r\n&gt;&gt;&gt; class citrus(fruit):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def __init__(self):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 super().__init__()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 global x\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 x+=2\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"I'm citrus\")\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\r\n&gt;&gt;&gt; x<\/pre>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; lime=citrus()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">I&#8217;m a fruit<br \/>\nI&#8217;m citrus<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; x<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>3<\/p>\n<\/div>\n<h4>2. Python Multiple Inheritance<\/h4>\n<p>Multiple inheritance in Python occurs when a class inherits from multiple base classes.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; class Color:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; class Fruit:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; class Orange(Color,Fruit):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; issubclass(Orange,Color) and issubclass(Orange,Fruit)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>True<\/p>\n<\/div>\n<h4>3. Multilevel Inheritance in Python<\/h4>\n<p>When one class inherits from another, which in turn inherits from another, it is multilevel Python inheritance.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; class A:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 x=1 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\r\n&gt;&gt;&gt; class B(A):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; class C(B):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; cobj=C()\r\n&gt;&gt;&gt; cobj.x<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>1<\/p>\n<\/div>\n<h4>4. Hierarchical Inheritance in Python<\/h4>\n<p>When more than one class inherits from a class, it is hierarchical Python inheritance.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; class A:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; class B(A):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; class C(A):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; issubclass(B,A) and issubclass(C,A)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>True<\/p>\n<\/div>\n<h4>5. Hybrid Inheritance in Python<\/h4>\n<p>Hybrid Python inheritance is a combination of any two kinds of inheritance.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; class A:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 x=1   \u00a0 \u00a0\u00a0\r\n&gt;&gt;&gt; class B(A):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; class C(A):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; class D(B,C):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 pass\r\n&gt;&gt;&gt; dobj=D()\r\n&gt;&gt;&gt; dobj.x\r\n<\/pre>\n<h4>Output<\/h4>\n<div class=\"code-output\">\n<p>1<\/p>\n<\/div>\n<h3>Python Inheritance Super Function &#8211; Super()<\/h3>\n<p>With inheritance, the super() function in Python actually comes in quite handy. It allows us to call a method from the parent class.<\/p>\n<p>Let\u2019s define a new class for this.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; class Vehicle:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def start(self):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"Starting engine\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def stop(self):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"Stopping engine\")\u00a0\u00a0 \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\r\n&gt;&gt;&gt; class TwoWheeler(Vehicle):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def say(self):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 super().start()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"I have two wheels\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 super().stop() \u00a0 \u00a0  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\r\n&gt;&gt;&gt; Pulsar=TwoWheeler()\r\n&gt;&gt;&gt; Pulsar.say()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Starting engine<br \/>\nI have two wheels<br \/>\nStopping engine<\/div>\n<h3>Python Override Method<\/h3>\n<p>A subclass may change the functionality of a Python method in the superclass. It does so by redefining it.<\/p>\n<p>This is termed Python method overriding. Let&#8217;s see this Python Method Overriding Example.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; class A:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def sayhi(self):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"I'm in A\")\u00a0\u00a0  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\r\n&gt;&gt;&gt; class B(A):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 def sayhi(self):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"I'm in B\")\u00a0 \u00a0  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\r\n&gt;&gt;&gt; bobj=B()\r\n&gt;&gt;&gt; bobj.sayhi()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>I&#8217;m in B<\/p>\n<\/div>\n<h3>Python Method Overloading<\/h3>\n<p><span style=\"font-weight: 400\">Before we say anything, we\u2019d like you to take a look at the following code:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def add(a,b):\r\n      return a+b\r\n&gt;&gt;&gt; def add(a,b,c):\r\n      return a+b+c\r\n&gt;&gt;&gt; add(2,3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Traceback (most recent call last):<br \/>\nFile &#8220;&lt;pyshell#8&gt;&#8221;, line 1, in &lt;module&gt;<br \/>\nadd(2,3)<br \/>\nTypeError: add() missing 1 required positional argument: &#8216;c&#8217;<\/div>\n<p><span style=\"font-weight: 400\">What looks like overloading methods, it is actually that Python keeps only the latest definition of a method you declare to it. <\/span><\/p>\n<p><span style=\"font-weight: 400\">This code doesn\u2019t make a call to the version of add() that takes in two arguments to add. So we find it safe to say Python doesn\u2019t support method overloading. <\/span><\/p>\n<p><span style=\"font-weight: 400\">However, we recently ran into a rather Pythonic way to make this happen. Check this out:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def add(instanceOf,*args):\r\n      if instanceOf=='int':\r\n              result=0\r\n      if instanceOf=='str':\r\n              result=''\r\n      for i in args:\r\n              result+=i\r\n      return result<\/pre>\n<p><span style=\"font-weight: 400\">In this code, not only do we use the *args magic variable for variable arity, but we also let the code deal with both integers and strings. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Watch it happen:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; add('int',3,4,5)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p><span style=\"font-family: Verdana, Geneva, sans-serif\">12<\/span><\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; add('str','I ','speak ','Python')<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>&#8216;I speak Python&#8217;<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">You say what if I do this?:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def add(a,b,c=0):<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>return a+b+c<\/p>\n<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; add(2,3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>5<\/p>\n<\/div>\n<p><span style=\"font-weight: 400\">To that, we\u2019ll say this isn\u2019t method overloading, this is simply the use of default arguments.<\/span><\/p>\n<h3>Python Interview Questions on Inheritance<\/h3>\n<p>1. How does inheritance work in Python?<\/p>\n<p>2. What are the types of inheritance in Python?<\/p>\n<p>3. Does Python support multiple inheritance?<\/p>\n<p>4. What is Python inheritance? Explain with an example.<\/p>\n<p>5. Is hierarchical inheritance possible in Python?<\/p>\n<h3>Conclusion<\/h3>\n<p>Of all things good, Python inheritance saves us time, effort, and memory.<\/p>\n<p>In this tutorial, we looked at Python inheritance syntax, inheritance types, Python method overloading, method overriding in Python, and Python super functions.<\/p>\n<p>Tell us in the comment box if something is missing.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python tutorial, we talk about Python inheritance and types of inheritance in Python with their syntax. Moreover, we will study Python super function, Python method overriding, and method overloading in Python. So,&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":6934,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[6706,8931,10583,10586,10596,10681,10682,10690,10692,10839,10874,15097],"class_list":["post-6887","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-inheritance-in-python-example","tag-multilevel-inheritance-in-python","tag-python-hierarchical-inheritance","tag-python-hybrid-inheritance","tag-python-inheritance-super","tag-python-method-overloading","tag-python-method-overriding","tag-python-multilevel-inheritance","tag-python-multiple-inheritance","tag-python-single-inheritance","tag-python-super-function","tag-types-of-python-inheritance"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Inheritance - Method Overloading &amp; Method Overriding - DataFlair<\/title>\n<meta name=\"description\" content=\"Python Inheritance - Syntax, types &amp; examples, Python Super function, Method overriding in python, python method overloading\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-inheritance\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Inheritance - Method Overloading &amp; Method Overriding - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python Inheritance - Syntax, types &amp; examples, Python Super function, Method overriding in python, python method overloading\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-inheritance\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-02-01T01:27:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-28T05:48:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Python-Inheritance-01-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"5000\" \/>\n\t<meta property=\"og:image:height\" content=\"2617\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Inheritance - Method Overloading &amp; Method Overriding - DataFlair","description":"Python Inheritance - Syntax, types & examples, Python Super function, Method overriding in python, python method overloading","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-inheritance\/","og_locale":"en_US","og_type":"article","og_title":"Python Inheritance - Method Overloading &amp; Method Overriding - DataFlair","og_description":"Python Inheritance - Syntax, types & examples, Python Super function, Method overriding in python, python method overloading","og_url":"https:\/\/data-flair.training\/blogs\/python-inheritance\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-02-01T01:27:40+00:00","article_modified_time":"2026-04-28T05:48:21+00:00","og_image":[{"width":5000,"height":2617,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Python-Inheritance-01-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Inheritance &#8211; Method Overloading &amp; Method Overriding","datePublished":"2018-02-01T01:27:40+00:00","dateModified":"2026-04-28T05:48:21+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/"},"wordCount":778,"commentCount":14,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Python-Inheritance-01-1.jpg","keywords":["inheritance in python example","Multilevel Inheritance in Python","Python Hierarchical Inheritance","Python Hybrid Inheritance","python inheritance super","Python Method Overloading","Python Method Overriding","Python Multilevel Inheritance","Python Multiple Inheritance","Python Single Inheritance","Python super() function","Types of Python Inheritance"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-inheritance\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/","url":"https:\/\/data-flair.training\/blogs\/python-inheritance\/","name":"Python Inheritance - Method Overloading &amp; Method Overriding - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Python-Inheritance-01-1.jpg","datePublished":"2018-02-01T01:27:40+00:00","dateModified":"2026-04-28T05:48:21+00:00","description":"Python Inheritance - Syntax, types & examples, Python Super function, Method overriding in python, python method overloading","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-inheritance\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Python-Inheritance-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/02\/Python-Inheritance-01-1.jpg","width":5000,"height":2617,"caption":"Python Inheritance"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-inheritance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Inheritance &#8211; Method Overloading &amp; Method Overriding"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=6887"}],"version-history":[{"count":18,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6887\/revisions"}],"predecessor-version":[{"id":147981,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6887\/revisions\/147981"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/6934"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=6887"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=6887"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=6887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}