{"id":117,"date":"2026-03-02T08:56:17","date_gmt":"2026-03-02T03:56:17","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=117"},"modified":"2026-03-16T10:06:54","modified_gmt":"2026-03-16T05:06:54","slug":"multiple-inheritance","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/","title":{"rendered":"Multiple Inheritance"},"content":{"rendered":"\n<p>Multiple Inheritance is a feature in Object-Oriented Programming (OOP) where a child class inherits from more than one parent class.<\/p>\n\n\n\n<p>In simple words:<br>One child class \u2192 Multiple parent classes<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Use Multiple Inheritance?<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Combine features from multiple classes<\/li>\n\n\n\n<li>Promote code reuse<\/li>\n\n\n\n<li>Create flexible and modular designs<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Basic Syntax<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">class Parent1:<br>    passclass Parent2:<br>    passclass Child(Parent1, Parent2):<br>    pass<\/pre>\n\n\n\n<p>The child class can access methods and variables from both parent classes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Simple Example<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">class Father:<br>    def skill1(self):<br>        print(\"Gardening\")class Mother:<br>    def skill2(self):<br>        print(\"Cooking\")class Child(Father, Mother):<br>    def skill3(self):<br>        print(\"Programming\")c = Child()c.skill1()<br>c.skill2()<br>c.skill3()<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Gardening<br>Cooking<br>Programming<\/pre>\n\n\n\n<p>Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Child<\/code> inherits from both <code>Father<\/code> and <code>Mother<\/code><\/li>\n\n\n\n<li>It can use methods from both classes<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Constructor in Multiple Inheritance<\/strong><\/h2>\n\n\n\n<p>If both parent classes have constructors:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Father:<br>    def __init__(self):<br>        print(\"Father Constructor\")class Mother:<br>    def __init__(self):<br>        print(\"Mother Constructor\")class Child(Father, Mother):<br>    def __init__(self):<br>        super().__init__()c = Child()<\/pre>\n\n\n\n<p>Python follows something called <strong>MRO (Method Resolution Order)<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Method Resolution Order (MRO)<\/strong><\/h2>\n\n\n\n<p>MRO decides the order in which Python searches for methods in multiple inheritance.<\/p>\n\n\n\n<p>You can check it using:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">print(Child.__mro__)<\/pre>\n\n\n\n<p>Python searches from left to right in the inheritance list.<\/p>\n\n\n\n<p>In this case:<br>Child \u2192 Father \u2192 Mother \u2192 object<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Diamond Problem<\/strong><\/h2>\n\n\n\n<p>The diamond problem occurs when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Two parent classes inherit from the same base class<\/li>\n\n\n\n<li>A child class inherits from both of them<\/li>\n<\/ul>\n\n\n\n<p>Python solves this using MRO (C3 Linearization).<\/p>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class A:<br>    def show(self):<br>        print(\"Class A\")class B(A):<br>    passclass C(A):<br>    passclass D(B, C):<br>    passd = D()<br>d.show()<\/pre>\n\n\n\n<p>Python ensures <code>A<\/code> is only called once.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Key Points<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A class can inherit from multiple classes<\/li>\n\n\n\n<li>Order of parents matters<\/li>\n\n\n\n<li>Python uses MRO to resolve conflicts<\/li>\n\n\n\n<li><code>super()<\/code> works with MRO<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>When to Use Multiple Inheritance<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When combining independent features<\/li>\n\n\n\n<li>When designing mixin classes<\/li>\n\n\n\n<li>When behavior needs to be shared from multiple sources<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Key Takeaway<\/strong><\/h2>\n\n\n\n<p>Multiple Inheritance allows a class to inherit from more than one parent class.<\/p>\n\n\n\n<p>Python handles complexity using Method Resolution Order, making multiple inheritance powerful and manageable.<\/p>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773637654840\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > Advanced OOP > Multiple Inheritance<\/span><\/span><\/div>","protected":false},"menu_order":59,"template":"","class_list":["post-117","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Multiple Inheritance - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn multiple inheritance in Python, how classes inherit from multiple parents, and how MRO resolves method conflicts\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Multiple Inheritance - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn multiple inheritance in Python, how classes inherit from multiple parents, and how MRO resolves method conflicts\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-16T05:06:54+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/multiple-inheritance\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/multiple-inheritance\\\/\",\"name\":\"Multiple Inheritance - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-02T03:56:17+00:00\",\"dateModified\":\"2026-03-16T05:06:54+00:00\",\"description\":\"Learn multiple inheritance in Python, how classes inherit from multiple parents, and how MRO resolves method conflicts\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/multiple-inheritance\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/multiple-inheritance\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/multiple-inheritance\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > Advanced OOP > Multiple Inheritance\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Multiple Inheritance - One Language. Endless Possibilities","description":"Learn multiple inheritance in Python, how classes inherit from multiple parents, and how MRO resolves method conflicts","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:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/","og_locale":"en_US","og_type":"article","og_title":"Multiple Inheritance - One Language. Endless Possibilities","og_description":"Learn multiple inheritance in Python, how classes inherit from multiple parents, and how MRO resolves method conflicts","og_url":"https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-16T05:06:54+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/","url":"https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/","name":"Multiple Inheritance - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-02T03:56:17+00:00","dateModified":"2026-03-16T05:06:54+00:00","description":"Learn multiple inheritance in Python, how classes inherit from multiple parents, and how MRO resolves method conflicts","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/multiple-inheritance\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > Advanced OOP > Multiple Inheritance"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/117","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}