{"id":75712,"date":"2020-01-27T10:03:14","date_gmt":"2020-01-27T04:33:14","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=75712"},"modified":"2024-08-22T20:04:02","modified_gmt":"2024-08-22T14:34:02","slug":"python-inheritance","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/","title":{"rendered":"Python Inheritance &#8211; Learn to build relationship between classes"},"content":{"rendered":"<p>Inheritance is one of the foundational concepts of object-oriented programming, allowing new classes to inherit attributes and methods from existing ones. This promotes code reusability and establishes a natural hierarchy between classes, making the code more modular and easier to maintain. Inheritance is widely used in programming and is essential for building production-ready applications that are scalable and efficient. In this article, we will delve into the concept of Python inheritance, explore its benefits, and examine the different types of inheritance, such as single, multiple, and multilevel inheritance.<\/p>\n<h3>What is Inheritance in Python?<\/h3>\n<p><strong>Inheritance<\/strong> in <strong>object-oriented programming<\/strong> is inspired by the <strong>real-world inheritance<\/strong> in <strong>human beings<\/strong>. We <strong>acquire<\/strong> some of the <strong>traits<\/strong> of our <strong>parents during birth<\/strong>.<\/p>\n<p>In Python, <strong>inheritance<\/strong> is the <strong>capability<\/strong> of a <strong>class<\/strong> to pass some of its <strong>properties<\/strong> or <strong>methods<\/strong> to it\u2019s <strong>derived class(child class)<\/strong>. With <strong>inheritance<\/strong>, we build a <strong>relationship<\/strong> <strong>between classes<\/strong> based on how they are <strong>derived<\/strong>.<\/p>\n<p><strong>For example,<\/strong> every <strong>car<\/strong>, <strong>bus<\/strong>, <strong>bikes<\/strong> are <strong>vehicles<\/strong>.<\/p>\n<p>So we can <strong>build relationships<\/strong> between <strong>them<\/strong> and a <strong>car<\/strong> can <strong>inherit things<\/strong> from the <strong>vehicle<\/strong>. This can be <strong>represented<\/strong> as the <strong>given image<\/strong>.<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/relationship-between-classes.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75813 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/relationship-between-classes.jpg\" alt=\"python inheritance - relationship between classes\" width=\"579\" height=\"299\" \/><\/a><\/p>\n<p>Here, the <strong>Vehicle<\/strong> will be called <strong>parent<\/strong> or <strong>base class<\/strong> while the <strong>car<\/strong>, <strong>bus<\/strong>, and <strong>bike<\/strong> are its <strong>child<\/strong> or <strong>derived class<\/strong>.<\/p>\n<h3>Python Inheritance Example<\/h3>\n<p>To derive a <strong>class<\/strong> from <strong>another class<\/strong> we can simply use the <strong>name<\/strong> of the <strong>parent class<\/strong> in <strong>parentheses<\/strong> after the <strong>class name<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Fruit:\r\n  pass\r\n\r\nclass Apple(Fruit):\r\n  pass<\/pre>\n<p>Here, we have defined <strong>two classes Fruit<\/strong> and <strong>Apple<\/strong>. The <strong>Apple class<\/strong> is <strong>derived<\/strong> from the <strong>Fruit class<\/strong>.<\/p>\n<p>The <strong>pass statement<\/strong> is used to <strong>create<\/strong> an <strong>empty class<\/strong>. <strong>Python<\/strong> has an <strong>in-built <\/strong>function <strong>issubclass()<\/strong> to <strong>check<\/strong> if a <strong>class<\/strong> is a <strong>subclass<\/strong> <strong>of another<\/strong> or <strong>not<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">issubclass(Apple, Fruit)<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">True<\/div>\n<h3>Types of Inheritance in Python<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/types-of-python-inheritance.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75806 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/types-of-python-inheritance.jpg\" alt=\"types of python inheritance\" width=\"790\" height=\"310\" \/><\/a><\/h3>\n<p>We can <strong>build<\/strong> different <strong>types<\/strong> of <strong>relationships<\/strong> between <strong>classes<\/strong> by the way they are <strong>inherited<\/strong>. Python has <strong>5 types<\/strong> of <strong>inheritance<\/strong>. Let\u2019s go through each of them.<\/p>\n<h4>1. Single Inheritance in Python<\/h4>\n<p>In single inheritance, a single class inherits from a class. This is the simplest form of inheritance, where the subclass inherits all the attributes and methods of the parent class. It allows the subclass to reuse and extend the functionality of the parent class, promoting code reusability and reducing redundancy.<\/p>\n<p>For example, if we have a Person class, a Student class can inherit from it, gaining all the properties and behaviors defined in the Person class while adding its own unique attributes and methods. Single inheritance helps create a clear and straightforward class hierarchy.<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/single-inheritance-in-python.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75808 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/single-inheritance-in-python.jpg\" alt=\"single inheritance in python\" width=\"429\" height=\"241\" \/><\/a><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class Parent:\r\n    def show(self):\r\n        print(\"Parent method\")\r\n\r\nclass Child(Parent):\r\n    def display(self):\r\n        print(\"Child method\")\r\n\r\n\r\nc = Child()\r\nc.display()\r\nc.show()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Child method<br \/>\nParent method<\/div>\n<p>Here, we <strong>created<\/strong> an <strong>object<\/strong> of the <strong>Child class<\/strong> and we saw that from the <strong>Child object<\/strong> we can even <strong>call<\/strong> the <strong>method<\/strong> of <strong>Parent class<\/strong>. This is the <strong>advantage <\/strong>of <strong>inheritance<\/strong>, we can <strong>reuse<\/strong> the <strong>code<\/strong> we have <strong>written<\/strong>.<\/p>\n<h4>2. Multilevel Inheritance in Python<\/h4>\n<p>Python supports multilevel inheritance, which means that there is <strong>no limit<\/strong> on the <strong>number of levels<\/strong> that you can <strong>inherit<\/strong>. In multilevel inheritance, a class inherits from a parent class, which in turn inherits from another parent class, forming a chain of inheritance. This allows for a more detailed and structured hierarchy, where each level can add specific functionalities.<\/p>\n<p>For example, if you have a Vehicle class, a Car class can inherit from it, and a SportsCar class can further inherit from the Car class, each adding its own unique attributes and behaviors.<br \/>\n<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/multilevel-inheritance-in-python.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75809 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/multilevel-inheritance-in-python.jpg\" alt=\"multilevel inheritance in python\" width=\"419\" height=\"352\" \/><\/a><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class A:\r\n    def methodA(self):\r\n        print(\"A class\")\r\n\r\nclass B(A):\r\n    def methodB(self):\r\n        print(\"B class\")\r\n\r\nclass C(B):\r\n    def methodC(self):\r\n        print(\"C class\")\r\n\r\nc = C()\r\nc.methodA()\r\nc.methodB()\r\nc.methodC()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">A class<br \/>\nB class<br \/>\nC class<\/div>\n<p>Here, the <strong>object <\/strong>of <strong>C class<\/strong> can <strong>access<\/strong> the <strong>methods<\/strong> and <strong>properties<\/strong> of <strong>both A<\/strong> and <strong>B class<\/strong> because they were <strong>inherited<\/strong> from <strong>top to bottom<\/strong>. But take note that the <strong>object<\/strong> of a <strong>B class<\/strong> <strong>cannot access<\/strong> methods of the <strong>C class<\/strong>.<\/p>\n<h4>3. Multiple Inheritance in Python<\/h4>\n<p>Till now, we were <strong>inheriting<\/strong> from only <strong>one class<\/strong> at a <strong>time<\/strong>.<\/p>\n<p>In <strong>multiple inheritance<\/strong>, we will see that <strong>Python<\/strong> also <strong>allows us<\/strong> to <strong>inherit<\/strong> from <strong>more than one class<\/strong>. To achieve this we can provide <strong>multiple classes separated<\/strong> by <strong>commas<\/strong>.<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/multiple-inheritance-in-python.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75810 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/multiple-inheritance-in-python.jpg\" alt=\"multiple python inheritance\" width=\"637\" height=\"294\" \/><\/a><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class A:\r\n    def methodA(self):\r\n        print(\"A class\")\r\n\r\nclass B:\r\n    def methodB(self):\r\n        print(\"B class\")\r\n\r\nclass C:\r\n    def methodC(self):\r\n        print(\"C class\")\r\n\r\nclass D(A, B, C):\r\n    def methodD(self):\r\n        print(\"D class\")\r\n\r\nd = D()\r\nd.methodA()\r\nd.methodB()\r\nd.methodC()\r\nd.methodD()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">A class<br \/>\nB class<br \/>\nC class<br \/>\nD class<\/div>\n<p>The <strong>object<\/strong> of a <strong>D class<\/strong> has <strong>directly inherited<\/strong> the <strong>properties<\/strong> and <strong>methods<\/strong> of <strong>A<\/strong>, <strong>B<\/strong>, and <strong>C classes<\/strong>.<\/p>\n<h4>4. Hierarchical Inheritance in Python<\/h4>\n<p>In a <strong>hierarchical <\/strong>inheritance, a <strong>class<\/strong> is <strong>inherited<\/strong> by <strong>more than one class<\/strong>. It is <strong>simple<\/strong> to <strong>understand<\/strong> with a <strong>diagram<\/strong>.<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/hierarchial-inheritance-in-python.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75812 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/hierarchial-inheritance-in-python.jpg\" alt=\"hierarchical python inheritance\" width=\"442\" height=\"374\" \/><\/a><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class A:\r\n    def methodA(self):\r\n        print(\"A class\")\r\n\r\nclass B(A):\r\n    def methodB(self):\r\n        print(\"B class\")\r\n\r\nclass C(A):\r\n    def methodC(self):\r\n        print(\"C class\")\r\n\r\nb = B()\r\nc = C()\r\n\r\nb.methodA()\r\nc.methodA()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">A class<br \/>\nA class<\/div>\n<h4>5. Hybrid Inheritance in Python<\/h4>\n<p>The term <strong>Hybrid<\/strong> describes that it is a <strong>mixture<\/strong> of <strong>more than one type<\/strong>. <strong>Hybrid inheritance<\/strong> is a <strong>combination<\/strong> of <strong>different types<\/strong> of <strong>inheritance<\/strong>.<a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/hybrid-inheritance-in-python.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-75909 size-full\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/01\/hybrid-inheritance-in-python.jpg\" alt=\"hybrid python inheritance\" width=\"386\" height=\"378\" \/><\/a><\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class A:\r\n    def methodA(self):\r\n        print(\"A class\")\r\n\r\nclass B(A):\r\n    def methodB(self):\r\n        print(\"B class\")\r\n\r\nclass C(A):\r\n    def methodC(self):\r\n        print(\"C class\")\r\n\r\nclass D(B,C):\r\n    def methodD(self):\r\n        print(\"D class\")\r\n\r\nd = D()\r\nd.methodA()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">A class<\/div>\n<h3>Python Inheritance &#8211; super() function<\/h3>\n<p>When dealing with <strong>inheritance<\/strong>, <strong>super()<\/strong> is a very <strong>handy function<\/strong>. <strong>super()<\/strong> is a <strong>proxy object<\/strong> which is used to <strong>refer<\/strong> to the <strong>parent object<\/strong>. We can <strong>call super()<\/strong> method to <strong>access<\/strong> the <strong>properties<\/strong> or <strong>methods<\/strong> of the <strong>parent class<\/strong>.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class A:\r\n    x=100\r\n    def methodA(self):\r\n        print(\"A class\")\r\n\r\nclass B(A):\r\n    def methodB(self):\r\n        super().methodA()\r\n        print(\"B class\")\r\n        print(super().x)\r\n\r\n\r\nb = B()\r\nb.methodB()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">A class<br \/>\nB class<br \/>\n100<\/div>\n<h3>Python Overriding Methods<\/h3>\n<p><strong>Method overriding<\/strong> is an important concept in<strong> object-oriented programming<\/strong>. Method overriding allows us to <strong>redefine<\/strong> a method by <strong>overriding<\/strong> it.<\/p>\n<p>For method overriding, we must satisfy <strong>two conditions<\/strong>:<\/p>\n<ul>\n<li>There should be a <strong>parent-child relationship<\/strong> between the <strong>classes<\/strong>.<\/li>\n<li><strong>Inheritance<\/strong> is a must.<\/li>\n<li>The name of the <strong>method<\/strong> and the <strong>parameters<\/strong> should be the <strong>same<\/strong> in the <strong>base<\/strong> and <strong>derived<\/strong> <strong>class<\/strong> in order to <strong>override<\/strong> it.<\/li>\n<\/ul>\n<p>What will happen when the method in the <strong>base<\/strong> and <strong>derived class<\/strong> are the same. Let\u2019s see an example of this.<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">class A:\r\n    def method(self):\r\n        print(\"A class\")\r\n\r\nclass B(A):\r\n    def method(self):\r\n        print(\"B class\")\r\n\r\nb = B()\r\nb.method()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">B class<\/div>\n<p>Here, the <strong>B class<\/strong> has <strong>inherited<\/strong> A class and we have the <strong>same function<\/strong> in both <strong>classes method()<\/strong>.<\/p>\n<p>Since the <strong>name<\/strong> and <strong>parameters<\/strong> are the <strong>same<\/strong>, the <strong>derived class<\/strong> <strong>overrides<\/strong> the method of the <strong>base class<\/strong> and when we call the <strong>method()<\/strong> the <strong>B class<\/strong> method is <strong>called<\/strong>. This is known as <strong>method<\/strong> <strong>overriding<\/strong>.<\/p>\n<h3>Overloading Methods in Python<\/h3>\n<p>If you have some experience with <strong>object-oriented programming<\/strong> or <strong>other languages<\/strong> like <strong>C\/C++<\/strong> or <strong>Java<\/strong> then you might have used <strong>method overloading<\/strong>. That is why it is important to understand that <strong>Python<\/strong> <strong>doesn\u2019t support<\/strong> <strong>method overloading<\/strong>.<\/p>\n<p>Let\u2019s see the example &#8211;<\/p>\n<p><strong>Code:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def getDetails():\r\n    print(\"Name: Default\")\r\n\r\ndef getDetails(name):\r\n    print(\"Name:\", name)\r\n\r\ngetDetails(\"Siri\")\r\ngetDetails()<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"code-output\">Name: Siri<br \/>\nTraceback (most recent call last):<br \/>\n<b>\u00a0\u00a0<\/b>File\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 &#8220;C:\\Users\\Techvidvan\\AppData\\Local\\Programs\\Python\\Python38-32\\test.py&#8221;, line 8, in &lt;module&gt;<br \/>\n<b>\u00a0\u00a0\u00a0\u00a0<\/b>getDetails()<br \/>\nTypeError: getDetails() missing 1 required positional argument: &#8216;name&#8217;<\/div>\n<p>As you can see, the<strong> getDetails(\u201cSiri\u201d)<\/strong> function got <strong>executed<\/strong> but the <strong>getDetails()<\/strong> was<strong> not executed<\/strong>.<\/p>\n<p>This is because <strong>Python overwrites<\/strong> the <strong>function<\/strong> with the <strong>same name<\/strong> and the <strong>latter function<\/strong> is <strong>used<\/strong>.<\/p>\n<h3>Summary<\/h3>\n<p>In this article, we discussed a very important <strong>concept<\/strong> of <strong>object-oriented programming<\/strong> i.e. <strong>Python Inheritance<\/strong>. We saw how we can <strong>pass properties<\/strong> or <strong>methods<\/strong> from <strong>one class<\/strong> to <strong>another<\/strong> using <strong>inheritance<\/strong>.<\/p>\n<p>In this Python inheritance article, we have also covered its <strong>types<\/strong>, <strong>functions<\/strong>, and <strong>methods<\/strong>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Inheritance is one of the foundational concepts of object-oriented programming, allowing new classes to inherit attributes and methods from existing ones. This promotes code reusability and establishes a natural hierarchy between classes, making the&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":75814,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1053],"tags":[1450,1451,1452,1453,1454,1455,1456,1457,1458,1459,1460],"class_list":["post-75712","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-hierarchical-inheritance-in-python","tag-hybrid-inheritance-in-python","tag-inheritance-in-python","tag-multilevel-inheritance-in-python","tag-multiple-inheritance-in-python","tag-overloading-methods-in-python","tag-python-inheritance","tag-python-inheritance-example","tag-python-overriding-methods","tag-single-inheritance-in-python","tag-types-of-inheritance-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Inheritance - Learn to build relationship between classes - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn the concept of inheritance in Python with its types. See Python inheritance functions and Python overriding &amp; overloading methods.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/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 - Learn to build relationship between classes - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn the concept of inheritance in Python with its types. See Python inheritance functions and Python overriding &amp; overloading methods.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-27T04:33:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-22T14:34:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-inheritance.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Inheritance - Learn to build relationship between classes - TechVidvan","description":"Learn the concept of inheritance in Python with its types. See Python inheritance functions and Python overriding & overloading methods.","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:\/\/techvidvan.com\/tutorials\/python-inheritance\/","og_locale":"en_US","og_type":"article","og_title":"Python Inheritance - Learn to build relationship between classes - TechVidvan","og_description":"Learn the concept of inheritance in Python with its types. See Python inheritance functions and Python overriding & overloading methods.","og_url":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2020-01-27T04:33:14+00:00","article_modified_time":"2024-08-22T14:34:02+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-inheritance.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Python Inheritance &#8211; Learn to build relationship between classes","datePublished":"2020-01-27T04:33:14+00:00","dateModified":"2024-08-22T14:34:02+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/"},"wordCount":1114,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-inheritance.jpg","keywords":["Hierarchical Inheritance in python","Hybrid Inheritance in Python","inheritance in python","Multilevel Inheritance in Python","Multiple Inheritance in Python","Overloading Methods in Python","Python Inheritance","Python Inheritance Example","Python Overriding Methods","Single Inheritance in Python","Types of Inheritance in Python"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/python-inheritance\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/","url":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/","name":"Python Inheritance - Learn to build relationship between classes - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-inheritance.jpg","datePublished":"2020-01-27T04:33:14+00:00","dateModified":"2024-08-22T14:34:02+00:00","description":"Learn the concept of inheritance in Python with its types. See Python inheritance functions and Python overriding & overloading methods.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/python-inheritance\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-inheritance.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2020\/01\/python-inheritance.jpg","width":802,"height":420,"caption":"inheritance in python"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/python-inheritance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Python Inheritance &#8211; Learn to build relationship between classes"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=75712"}],"version-history":[{"count":2,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75712\/revisions"}],"predecessor-version":[{"id":447688,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/75712\/revisions\/447688"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/75814"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=75712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=75712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=75712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}