{"id":50232,"date":"2021-11-18T18:09:43","date_gmt":"2021-11-18T12:39:43","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/"},"modified":"2026-01-23T15:53:04","modified_gmt":"2026-01-23T10:23:04","slug":"inheritance-in-python","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/","title":{"rendered":"Inheritance in Python"},"content":{"rendered":"\n<p>Inheritance is a way to form relationships between classes. You have a \"parent\" class (also called a base class or superclass) and a \"child\" class (a derived class or subclass). The child class gets all the methods and properties of the parent class. That's it. It\u2019s a mechanism for code reuse. Don't repeat yourself (DRY) is a core programming principle, and inheritance is one way to achieve it.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-use-it\">Why use it?<\/h2>\n\n\n\n<p>Imagine you're coding a game. You have Enemy objects. Goblins, Orcs, and Dragons are all enemies. They all have health, can take damage, and can attack. Instead of writing that code three times, you create a base Enemy class with that shared logic. Then, your Goblin, Orc, and Dragon classes can inherit from Enemy. They get all the Enemy functionality for free, and you can add specific things to each, like a Dragon's <code>breathe_fire()<\/code> method.<\/p>\n\n\n\n<p>Here's the basic syntax. No magic here.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Parent class\nclass Enemy:\n    def __init__(self, name, health):\n        self.name = name\n        self.health = health\n\n    def take_damage(self, amount):\n        self.health -= amount\n        print(f&quot;{self.name} takes {amount} damage, {self.health} HP left.&quot;)\n\n# Child class\nclass Goblin(Enemy):\n    # This class is empty, but it already has everything from Enemy\n    pass\n\n# Let&#039;s use it\ngrog = Goblin(&quot;Grog the Goblin&quot;, 50)\ngrog.take_damage(10)  # This method comes from the Enemy class\n# Output: Grog the Goblin takes 10 damage, 40 HP left.\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"types-of-inheritance\">Types of Inheritance<\/h2>\n\n\n\n<p>There are a few ways to structure this parent-child relationship.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-single-inheritance\">1. Single Inheritance<\/h3>\n\n\n\n<p>This is what you just saw. One child class inherits from one parent class. It's the simplest and most common form of inheritance. <code>Square<\/code> inherits from <code>Rectangle<\/code>, <code>Rectangle<\/code> inherits from <code>Shape<\/code>. Clean and linear.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-multilevel-inheritance\">2. Multilevel Inheritance<\/h3>\n\n\n\n<p>This is just a chain of single inheritance. A is the grandparent, B is the parent, and C is the child. C inherits from B, and B inherits from A. This means C gets all the methods and properties from both B and A.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Organism:\n    def breathe(self):\n        print(&quot;Inhale, exhale.&quot;)\n\nclass Animal(Organism):\n    def move(self):\n        print(&quot;Moving around.&quot;)\n\nclass Dog(Animal):\n    def bark(self):\n        print(&quot;Woof!&quot;)\n\nmy_dog = Dog()\nmy_dog.bark()   # From Dog\nmy_dog.move()   # From Animal\nmy_dog.breathe() # From Organism\n<\/pre><\/div>\n\n\n<p>This can get messy if the chain is too long. Deep inheritance hierarchies are often a sign of bad design.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-multiple-inheritance\">3. Multiple Inheritance<\/h3>\n\n\n\n<p>This is where a single child class inherits from multiple parent classes at the same time. This is where Python gets powerful, and also dangerous.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Flyer:\n    def fly(self):\n        print(&quot;I am flying.&quot;)\n\nclass Swimmer:\n    def swim(self):\n        print(&quot;I am swimming.&quot;)\n\nclass Duck(Flyer, Swimmer):\n    def quack(self):\n        print(&quot;Quack!&quot;)\n\ndonald = Duck()\ndonald.fly()\ndonald.swim()\ndonald.quack()\n<\/pre><\/div>\n\n\n<p>The <code>Duck<\/code> class can both fly and swim because it inherits from both <code>Flyer<\/code> and <code>Swimmer<\/code>. This sounds great, but it introduces a major problem: What if both parent classes have a method with the same name? This is known as the \"<a href=\"https:\/\/en.wikipedia.org\/wiki\/Diamond_problem\" target=\"_blank\" rel=\"noopener\">Diamond Problem<\/a>,\" and it leads us to the next critical topic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"method-resolution-order-mro\">Method Resolution Order (MRO)<\/h2>\n\n\n\n<p>When you call a method on an object from a class that uses multiple inheritance, how does Python know which parent's method to use? It follows a specific order called the Method Resolution Order (<a href=\"https:\/\/docs.python.org\/3\/glossary.html#term-method-resolution-order\" target=\"_blank\" rel=\"noopener\">MRO<\/a>).<\/p>\n\n\n\n<p>The MRO defines the sequence of classes to search when looking for a method. Python uses an algorithm called C3 linearization to figure this out. The key rules are that a child class is checked before its parents, and if there are multiple parents, they are checked in the order you list them in the class definition.<\/p>\n\n\n\n<p>You can see the MRO for any class by using the <code>.mro()<\/code> method or the <code>__mro__<\/code> attribute.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass A: pass\nclass B(A): pass\nclass C(A): pass\nclass D(B, C): pass\n\nprint(D.mro())\n<\/pre><\/div>\n\n\n<p>Output:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&#x5B;&amp;lt;class &#039;__main__.D&#039;&gt;, &amp;lt;class &#039;__main__.B&#039;&gt;, &amp;lt;class &#039;__main__.C&#039;&gt;, &amp;lt;class &#039;__main__.A&#039;&gt;, &amp;lt;class &#039;object&#039;&gt;]\n<\/pre><\/div>\n\n\n<p>When you call a method on a <code>D<\/code> object, Python will look for it in this order: <code>D<\/code>, then <code>B<\/code>, then <code>C<\/code>, then <code>A<\/code>, and finally the base object class that everything in Python inherits from. The first place it finds the method, it stops and uses that one. This predictability is crucial for managing complex inheritance structures.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-super-function-your-best-friend-in-inheritance\">The super() Function: Your Best Friend in Inheritance<\/h2>\n\n\n\n<p>When you have a child class, you often want to extend the parent's method, not completely replace it. For example, in the child's <code>__init__<\/code>, you first need to run the parent's <code>__init__<\/code> to set up all the inherited attributes.<\/p>\n\n\n\n<p>You do this with <code>super()<\/code>. The <code>super()<\/code> function gives you a way to call the parent class's methods. More accurately, it allows you to call the next method in the MRO chain.<\/p>\n\n\n\n<p>Let's fix our <code>Enemy<\/code> example to add a Goblin-specific attribute.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Enemy:\n    def __init__(self, name, health):\n        self.name = name\n        self.health = health\n\nclass Goblin(Enemy):\n    def __init__(self, name, health, has_club):\n        # Call the parent&#039;s __init__ to handle name and health\n        super().__init__(name, health)\n        # Now add the child-specific attribute\n        self.has_club = has_club\n\ngrog = Goblin(&quot;Grog&quot;, 50, True)\nprint(grog.name)       # Output: Grog\nprint(grog.has_club)  # Output: True\n<\/pre><\/div>\n\n\n<p>Without <code>super().__init__(name, health)<\/code>, the <code>grog<\/code> object would never get its <code>.name<\/code> or <code>.health<\/code> attributes because the <code>Enemy.__init__<\/code> would never be called. You replaced it, but you didn't extend it. <code>super()<\/code> solves this.<\/p>\n\n\n\n<p><code>super()<\/code> is essential for making multiple inheritance work properly. If you call parent methods directly by name (e.g., <code>B.__init__(self, ...)<\/code>), you can end up calling the same method from a common ancestor multiple times, which leads to bugs. <code>super()<\/code> respects the MRO and ensures each method in the inheritance chain is called only once.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"is-inheritance-always-the-answer-no\">Is Inheritance Always the Answer? (No.)<\/h2>\n\n\n\n<p>Inheritance is a powerful tool, but it's often overused by beginners. It creates a tight coupling between your classes. A change in the parent can break all the children.<\/p>\n\n\n\n<p>The main alternative is <a href=\"https:\/\/en.wikipedia.org\/wiki\/Composition_over_inheritance\" target=\"_blank\" rel=\"noopener\">Composition<\/a>. Instead of a class being something (inheritance), it has something (composition).<\/p>\n\n\n\n<p>Let's say you have a <code>Car<\/code> class. You could have it inherit from a <code>Vehicle<\/code> class. But what about its engine? A <code>Car<\/code> isn't an <code>Engine<\/code>, a <code>Car<\/code> has an <code>Engine<\/code>. So you would create a separate <code>Engine<\/code> class and give your <code>Car<\/code> an <code>engine<\/code> attribute that is an instance of the <code>Engine<\/code> class.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Engine:\n    def start(self):\n        print(&quot;Engine starts.&quot;)\n\nclass Car:\n    def __init__(self, make):\n        self.make = make\n        self.engine = Engine()  # Composition: Car HAS AN Engine\n\n    def drive(self):\n        self.engine.start()\n        print(f&quot;The {self.make} is driving.&quot;)\n\nmy_car = Car(&quot;Ford&quot;)\nmy_car.drive()\n<\/pre><\/div>\n\n\n<p>This is often more flexible. You can easily swap out the <code>Engine<\/code> object for a different one (e.g., <code>ElectricEngine<\/code>) without changing the <code>Car<\/code> class itself. The general rule is to \"favor composition over inheritance.\" If the relationship is not a clear \"is-a\" relationship (a Goblin is an Enemy), composition is probably the better design choice.<\/p>\n\n\n\n<p><strong>Also Read:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/\">Oops in Python<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/\">Polymorphism in Python<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/python-tutorial-for-beginners-a-complete-guide\/\">Python Tutorial<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Inheritance is a way to form relationships between classes. You have a \"parent\" class (also called a base class or superclass) and a \"child\" class (a derived class or subclass). The child class gets all the methods and properties of the parent class. That's it. It\u2019s a mechanism for code reuse. Don't repeat yourself (DRY) [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":111231,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796],"content_type":[],"class_list":["post-50232","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Inheritance in Python<\/title>\n<meta name=\"description\" content=\"Inheritance in Python is a technique used to build a new class based on existing ones. This article will teach you how to use inheritance in Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Inheritance in Python\" \/>\n<meta property=\"og:description\" content=\"Inheritance in Python is a technique used to build a new class based on existing ones. This article will teach you how to use inheritance in Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-18T12:39:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-01-23T10:23:04+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1194\" \/>\n\t<meta property=\"og:image:height\" content=\"722\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Inheritance in Python\",\"datePublished\":\"2021-11-18T12:39:43+00:00\",\"dateModified\":\"2026-01-23T10:23:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/\"},\"wordCount\":847,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/inheritance-in-python.webp\",\"keywords\":[\"python\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/\",\"name\":\"Inheritance in Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/inheritance-in-python.webp\",\"datePublished\":\"2021-11-18T12:39:43+00:00\",\"dateModified\":\"2026-01-23T10:23:04+00:00\",\"description\":\"Inheritance in Python is a technique used to build a new class based on existing ones. This article will teach you how to use inheritance in Python.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/inheritance-in-python.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/11\\\/inheritance-in-python.webp\",\"width\":1194,\"height\":722},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/inheritance-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Inheritance in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Inheritance in Python","description":"Inheritance in Python is a technique used to build a new class based on existing ones. This article will teach you how to use inheritance in Python.","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:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Inheritance in Python","og_description":"Inheritance in Python is a technique used to build a new class based on existing ones. This article will teach you how to use inheritance in Python.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-11-18T12:39:43+00:00","article_modified_time":"2026-01-23T10:23:04+00:00","og_image":[{"width":1194,"height":722,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp","type":"image\/webp"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Inheritance in Python","datePublished":"2021-11-18T12:39:43+00:00","dateModified":"2026-01-23T10:23:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/"},"wordCount":847,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp","keywords":["python"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/","url":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/","name":"Inheritance in Python","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp","datePublished":"2021-11-18T12:39:43+00:00","dateModified":"2026-01-23T10:23:04+00:00","description":"Inheritance in Python is a technique used to build a new class based on existing ones. This article will teach you how to use inheritance in Python.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp","width":1194,"height":722},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/inheritance-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Inheritance in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp",1194,722,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python-300x181.webp",300,181,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python-768x464.webp",768,464,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python-1024x619.webp",1024,619,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp",1194,722,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python.webp",1194,722,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python-640x722.webp",640,722,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/11\/inheritance-in-python-150x91.webp",150,91,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Inheritance is a way to form relationships between classes. You have a \"parent\" class (also called a base class or superclass) and a \"child\" class (a derived class or subclass). The child class gets all the methods and properties of the parent class. That's it. It\u2019s a mechanism for code reuse. Don't repeat yourself (DRY)&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/50232","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=50232"}],"version-history":[{"count":8,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/50232\/revisions"}],"predecessor-version":[{"id":115337,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/50232\/revisions\/115337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/111231"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=50232"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=50232"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=50232"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=50232"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}