{"id":2660,"date":"2026-10-20T11:14:38","date_gmt":"2026-10-20T11:14:38","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=2660"},"modified":"2026-10-22T02:26:18","modified_gmt":"2026-10-22T02:26:18","slug":"python-inheritance-tutorial","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/","title":{"rendered":"Python Inheritance Tutorial"},"content":{"rendered":"<h1><strong><b>Python Inheritance Tutorial: Types, super() and Examples<\/b><\/strong><\/h1>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Imagine you are writing a program for a sports shop. You write a class for sports items with a model, a colour and a cost. Next, you need a class for shoes, which has all of those and a brand as well. Do you copy the first class and add one line? You could, but then every fix must be made twice, and one copy will soon be wrong. Inheritance is the way out.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Inheritance lets a new class take everything an existing class has, and then add or change only what is different. The existing class is called the parent, and the new one is the child. It is one of the four main ideas of object oriented programming, with encapsulation, polymorphism and abstraction, and you will find it in almost every large Python project.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">In this tutorial, we begin with a tiny working example and then build a real one with a parent, a child and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">super()<\/code>. We cover all the types of inheritance with tested code, method overriding, the method resolution order, and the mistakes that cause errors. Everything below was run, and the output shown is the real output.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">What is Inheritance in Python?<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Inheritance is the ability of one class to use the attributes and methods of another class. The class that gives is the parent class, also called the superclass or base class. The class that receives is the child class, also called the subclass or derived class.<\/p>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The main benefits are:<\/p>\n<ul style=\"font-family: Arial,Helvetica,sans-serif; margin: 0 0 16px; padding-left: 24px; font-size: 17px; line-height: 1.7; color: #1f2937;\">\n<li style=\"margin: 0 0 8px;\"><strong>Reuse.<\/strong> Write the common code once, in the parent, and every child gets it.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>One place to fix.<\/strong> A bug fixed in the parent is fixed for all children.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>Easy to extend.<\/strong> A child can add new methods, or change inherited ones, without touching the parent.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>Transitive.<\/strong> If C inherits from B, and B inherits from A, then C also gets everything from A.<\/li>\n<\/ul>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A simple test for good use: the sentence child is a kind of parent should sound right. A dog is a kind of animal, so <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Dog<\/code> can inherit from <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Animal<\/code>. Shoes are a kind of sports item, so that works too.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">How to Create a Child Class<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Put the name of the parent in brackets after the name of the child class.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class ChildClassName(ParentClassName):\r\n    # body of the child class<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Here is the smallest working example. The child class does nothing of its own, and it still can use the parent method:<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class Parent:\r\n    def greet(self):\r\n        print(\"Hello from the parent class\")\r\n\r\nclass Child(Parent):\r\n    pass\r\n\r\nChild().greet()<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">Hello from the parent class<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The word <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">pass<\/code> means do nothing, and it is needed because a class cannot be empty. Notice the indentation, which is four spaces. Python stops with an error when it is missing:<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class X:\r\ndef f(self):\r\n    pass<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">IndentationError: expected an indented block after class definition on line 1<\/pre>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Python Inheritance Example: SportsItem and Shoes<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Now a real one. The parent class <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">SportsItem<\/code> stores a model, a colour and a cost. Its child <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Shoes<\/code> adds a brand. <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Shoes<\/code> does not repeat any of the parent code.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class SportsItem:\r\n    def __init__(self, model, color, cost):\r\n        self.__model = model\r\n        self.__color = color\r\n        self.__cost = cost\r\n\r\n    def get_model(self):\r\n        return self.__model\r\n\r\n    def get_color(self):\r\n        return self.__color\r\n\r\n    def set_color(self, color):\r\n        self.__color = color\r\n\r\n    def get_cost(self):\r\n        return self.__cost\r\n\r\n    def set_cost(self, cost):\r\n        self.__cost = cost\r\n\r\n\r\nclass Shoes(SportsItem):\r\n    def __init__(self, model, color, cost, brand):\r\n        super().__init__(model, color, cost)\r\n        self.__brand = brand\r\n\r\n    def info(self):\r\n        return (self.get_model() + \" of brand \" + self.__brand + \" in \"\r\n                + self.get_color() + \" color for Rs.\" + str(self.get_cost()))\r\n\r\nsh1 = Shoes(\"Shoes\", \"Black\", 3699, \"Xyz123\")\r\nprint(sh1.info())\r\nprint(sh1.get_model())\r\nsh2 = Shoes(\"Shoes\", \"Black red\", 4599, \"Xyz345\")\r\nprint(sh2.info())\r\nsh2.set_cost(3999)\r\nprint(sh2.info())<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">Shoes of brand Xyz123 in Black color for Rs.3699\r\nShoes\r\nShoes of brand Xyz345 in Black red color for Rs.4599\r\nShoes of brand Xyz345 in Black red color for Rs.3999<\/pre>\n<\/div>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Notes on the Code<\/h3>\n<ul style=\"font-family: Arial,Helvetica,sans-serif; margin: 0 0 16px; padding-left: 24px; font-size: 17px; line-height: 1.7; color: #1f2937;\">\n<li style=\"margin: 0 0 8px;\">There is one <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_color<\/code> and one <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">set_cost<\/code> method.<\/li>\n<li style=\"margin: 0 0 8px;\">Method names use lower case with underscores, the usual Python style.<\/li>\n<li style=\"margin: 0 0 8px;\">The cost is stored as a number and is turned into text only in the output.<\/li>\n<\/ul>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">The Private Name Trap<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Look at the double underscore in <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">self.__model<\/code>. Python changes such a name inside the class, so it is hard to reach from outside, and that includes child classes. A child must use the parent methods, such as <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">get_model<\/code>, to read it. Here is what happens when a child tries to read it directly:<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class BadShoes(SportsItem):\r\n    def show(self):\r\n        return self.__model\r\n\r\nBadShoes(\"Shoes\", \"Black\", 3699).show()<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">AttributeError: 'BadShoes' object has no attribute '_BadShoes__model'<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">If you want a child to read a value directly, use a single underscore, such as <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">self._model<\/code>. It is a signal to other programmers that the value is for internal use, and Python does not rename it.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">How super() Works in Python<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The function <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">super()<\/code> gives you access to the parent class from inside the child. You use it for two main jobs.<\/p>\n<ul style=\"font-family: Arial,Helvetica,sans-serif; margin: 0 0 16px; padding-left: 24px; font-size: 17px; line-height: 1.7; color: #1f2937;\">\n<li style=\"margin: 0 0 8px;\"><strong>To run the parent constructor.<\/strong> In the <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Shoes<\/code> class, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">super().__init__(model, color, cost)<\/code> lets the parent set up the model, colour and cost, so the child only deals with the brand.<\/li>\n<li style=\"margin: 0 0 8px;\"><strong>To call a parent method that the child has changed.<\/strong> This is shown in the next section.<\/li>\n<\/ul>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">If a child writes its own <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">__init__<\/code> and forgets to call the parent one, the parent values are never set. Python does not warn you. The error shows up later, when you use them:<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class ForgetfulShoes(SportsItem):\r\n    def __init__(self, brand):\r\n        self.brand = brand\r\n\r\nForgetfulShoes(\"Xyz\").get_model()<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">AttributeError: 'ForgetfulShoes' object has no attribute '_SportsItem__model'<\/pre>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Method Overriding<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A child can write a method with the same name as one in the parent. The child version is used for child objects. This is called overriding. Inside it, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">super()<\/code> lets you keep the parent behaviour and add to it.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class Animal:\r\n    def speak(self):\r\n        return \"Some sound\"\r\n\r\nclass Dog(Animal):\r\n    def speak(self):\r\n        return super().speak() + \", then Woof\"\r\n\r\nprint(Animal().speak())\r\nprint(Dog().speak())<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">Some sound\r\nSome sound, then Woof<\/pre>\n<\/div>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">isinstance and issubclass<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Two built in functions check the family tree. The first checks an object, and the second checks a class.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">d = Dog()\r\nprint(isinstance(d, Dog), isinstance(d, Animal), isinstance(Animal(), Dog))\r\nprint(issubclass(Dog, Animal), issubclass(Animal, Dog))<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">True True False\r\nTrue False<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Dog<\/code> object is also an <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Animal<\/code>, but an <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Animal<\/code> is not a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Dog<\/code>. The relation works in one direction only.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Types of Inheritance in Python<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Python programmers usually talk about five types.<\/p>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 760px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Types of inheritance in Python<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 160px;\" scope=\"col\">Type<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Meaning<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Example<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Single<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">One child, one parent<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Dog inherits from Animal<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Multilevel<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">A chain: a grandparent, a parent and a child<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">C inherits from B, and B from A<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Hierarchical<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Several children, one parent<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Square and Circle inherit from Shape<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Multiple<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">One child, two or more parents<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">MultiInher inherits from Super1 and Super2<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; vertical-align: top;\" scope=\"row\">Hybrid<\/th>\n<td style=\"padding: 12px 16px; vertical-align: top;\">A mix of the types above<\/td>\n<td style=\"padding: 12px 16px; vertical-align: top;\">Bottom inherits from Left and Right, which both inherit from Base<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Single Inheritance<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">This is the case we have already seen in <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Child<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Parent<\/code>, <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Dog<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Animal<\/code>, and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Shoes<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">SportsItem<\/code>.<\/p>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Multilevel Inheritance<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Each class inherits from the one before it. So <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">C<\/code> gets everything from <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">B<\/code> and <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">A<\/code>.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class A:\r\n    def who(self):\r\n        return \"A\"\r\n\r\nclass B(A):\r\n    pass\r\n\r\nclass C(B):\r\n    pass\r\n\r\nprint(C().who())\r\nprint([k.__name__ for k in C.__mro__])<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">A\r\n['C', 'B', 'A', 'object']<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">The second line shows the chain Python follows when it looks for a method. We explain it below.<\/p>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Hierarchical Inheritance<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Several children share one parent, and each changes the part that is different.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class Shape:\r\n    def area(self):\r\n        return 0\r\n\r\nclass Square(Shape):\r\n    def __init__(self, s):\r\n        self.s = s\r\n    def area(self):\r\n        return self.s * self.s\r\n\r\nclass Circle(Shape):\r\n    def __init__(self, r):\r\n        self.r = r\r\n    def area(self):\r\n        return round(3.14159 * self.r * self.r, 2)\r\n\r\nfor sh in (Square(4), Circle(3)):\r\n    print(type(sh).__name__, sh.area())<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">Square 16\r\nCircle 28.27<\/pre>\n<\/div>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Multiple Inheritance<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A child can have more than one parent. List them in brackets, separated by commas. It is not a list, it is a group of names written in the class line.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class Super1:\r\n    def __init__(self):\r\n        self.test1 = \"Python\"\r\n        print(\"Superclass1\")\r\n\r\nclass Super2:\r\n    def __init__(self):\r\n        self.test2 = \"Tutorials\"\r\n        print(\"Superclass2\")\r\n\r\nclass MultiInher(Super1, Super2):\r\n    def __init__(self):\r\n        Super1.__init__(self)\r\n        Super2.__init__(self)\r\n        print(\"Derived\")\r\n\r\n    def print_vals(self):\r\n        print(self.test1, self.test2)\r\n\r\nobj = MultiInher()\r\nobj.print_vals()<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">Superclass1\r\nSuperclass2\r\nDerived\r\nPython Tutorials<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Here the child calls each parent constructor by name. That works for a simple case. For bigger programs, the next section shows the cleaner way.<\/p>\n<h3 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 21px; line-height: 1.35; font-weight: bold; color: #0f2a4a; margin: 28px 0 10px;\">Hybrid Inheritance and the Diamond<\/h3>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Hybrid inheritance mixes the types. The best known shape is the diamond, where two classes inherit from the same base, and a fourth class inherits from both. Python handles it with <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">super()<\/code>, and each class calls the next one in line:<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class Base:\r\n    def hello(self):\r\n        return \"Base\"\r\n\r\nclass Left(Base):\r\n    def hello(self):\r\n        return \"Left then \" + super().hello()\r\n\r\nclass Right(Base):\r\n    def hello(self):\r\n        return \"Right then \" + super().hello()\r\n\r\nclass Bottom(Left, Right):\r\n    def hello(self):\r\n        return \"Bottom then \" + super().hello()\r\n\r\nprint(Bottom().hello())<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">Bottom then Left then Right then Base<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Notice that <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Base<\/code> runs only once, and that <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Right<\/code> runs even though <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Left<\/code> does not name it. This is the method resolution order at work.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Method Resolution Order (MRO)<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">When you call a method, Python searches the classes in a fixed order, and uses the first match. That order is the method resolution order. Print it with the <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">__mro__<\/code> attribute:<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">print([k.__name__ for k in Bottom.__mro__])<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">['Bottom', 'Left', 'Right', 'Base', 'object']<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Read it from left to right. A child comes before its parents, and the parents appear in the order you wrote them in the brackets. At the end of every chain sits <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">object<\/code>, the base of all classes in Python 3. So, if two parents define the same method, the one written first in the class line wins.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Inheritance or Composition?<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Inheritance is not always the right tool. Use it when the child really is a kind of the parent. Use composition when one thing has another. A car has an engine, but a car is not an engine, so the car holds an engine object:<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">class Engine:\r\n    def start(self):\r\n        return \"Engine started\"\r\n\r\nclass Car:\r\n    def __init__(self):\r\n        self.engine = Engine()\r\n    def start(self):\r\n        return self.engine.start()\r\n\r\nprint(Car().start())<\/pre>\n<div style=\"background: #1f2937; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">output<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #ffffff;\">Engine started<\/pre>\n<\/div>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">A good rule for new programmers: if the sentence is a kind of does not sound right, do not use inheritance.<\/p>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Common Inheritance Errors and How to Fix Them<\/h2>\n<div style=\"border: 1px solid #d9e0ea; border-radius: 8px; overflow-x: auto; margin: 20px 0; -webkit-overflow-scrolling: touch;\">\n<table style=\"width: 100%; min-width: 900px; border-collapse: collapse; font-family: Arial,Helvetica,sans-serif; font-size: 16px; line-height: 1.6; color: #1f2937;\">\n<caption style=\"caption-side: top; text-align: left; padding: 14px 16px; font-weight: bold; font-size: 17px; color: #0f2a4a;\">Inheritance errors and fixes<\/caption>\n<thead>\n<tr>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38; width: 330px;\" scope=\"col\">Error<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Usual cause<\/th>\n<th style=\"background: #0f2a4a; color: #ffffff; text-align: left; padding: 12px 16px; border-bottom: 2px solid #0b1f38;\" scope=\"col\">Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">IndentationError: expected an indented block<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">The class or method body is not indented<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Indent the body by four spaces<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">SyntaxError on classabc or defgetModel<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">A missing space after class or def<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Write class abc and def getModel<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">SyntaxError on a curly quote<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Text copied from a web page or a Word file<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Type straight quotes in your editor<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">AttributeError: object has no attribute _Class__name<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">A double underscore name used in a child, or the parent init was not called<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Use the parent method, or call super().__init__()<\/td>\n<\/tr>\n<tr style=\"background: #ffffff;\">\n<th style=\"text-align: left; padding: 12px 16px; border-bottom: 1px solid #e5e9f0; color: #0f2a4a; vertical-align: top;\" scope=\"row\">TypeError: missing required positional argument<\/th>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">The child init does not pass all values to the parent<\/td>\n<td style=\"padding: 12px 16px; border-bottom: 1px solid #e5e9f0; vertical-align: top;\">Pass every value that the parent init needs<\/td>\n<\/tr>\n<tr style=\"background: #f5f8fc;\">\n<th style=\"text-align: left; padding: 12px 16px; color: #0f2a4a; vertical-align: top;\" scope=\"row\">TypeError: Cannot create a consistent method resolution order (MRO)<\/th>\n<td style=\"padding: 12px 16px; vertical-align: top;\">A parent is listed before its own child, such as class C(A, B) when B inherits from A<\/td>\n<td style=\"padding: 12px 16px; vertical-align: top;\">Put the child first, as in class C(B, A)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Practice Exercises<\/h2>\n<ol style=\"font-family: Arial,Helvetica,sans-serif; margin: 0 0 16px; padding-left: 28px; font-size: 17px; line-height: 1.7; color: #1f2937;\">\n<li style=\"margin: 0 0 8px;\">Create a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Vehicle<\/code> class with a name and a speed. Create a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Car<\/code> class that inherits from it and adds a number of doors.<\/li>\n<li style=\"margin: 0 0 8px;\">Add a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">describe<\/code> method to <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Vehicle<\/code>, then override it in <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Car<\/code>, and use <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">super()<\/code> to keep the first part of the text.<\/li>\n<li style=\"margin: 0 0 8px;\">Add a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Bike<\/code> class as a second child of <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Vehicle<\/code>, and loop over a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Car<\/code> and a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Bike<\/code> calling <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">describe<\/code> on each.<\/li>\n<li style=\"margin: 0 0 8px;\">Print the method resolution order of <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Car<\/code>, and check with <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">isinstance<\/code> that a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Car<\/code> object is also a <code style=\"font-family: 'Courier New',Courier,monospace; font-size: 15px; background: #eef2f7; padding: 2px 6px; border-radius: 4px;\">Vehicle<\/code>.<\/li>\n<li style=\"margin: 0 0 8px;\">Build a diamond like the one above, then swap the order of the two parents and see how the output changes.<\/li>\n<\/ol>\n<h2 style=\"font-family: Arial,Helvetica,sans-serif; font-size: 26px; line-height: 1.3; font-weight: bold; color: #0f2a4a; margin: 36px 0 12px;\">Complete Script to Run Yourself<\/h2>\n<p style=\"font-family: Arial,Helvetica,sans-serif; font-size: 17px; line-height: 1.7; color: #1f2937; margin: 0 0 16px;\">Here is the full script that was used to test every example on this page. It ran on Python 3.13.<\/p>\n<div style=\"margin: 20px 0; border: 1px solid #d9e0ea; border-radius: 8px; overflow: hidden;\">\n<div style=\"background: #0f2a4a; color: #ffffff; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; padding: 8px 16px;\">python<\/div>\n<pre style=\"margin: 0; padding: 16px; color: #1f2937; font-family: 'Courier New',Courier,monospace; font-size: 14px; line-height: 1.7; overflow-x: auto; white-space: pre; background: #f5f8fc;\">import sys\r\n\r\n# 1. Smallest example\r\nclass Parent:\r\n    def greet(self):\r\n        print(\"Hello from the parent class\")\r\n\r\nclass Child(Parent):\r\n    pass\r\n\r\nChild().greet()\r\n\r\n# 2. Sports example\r\nclass SportsItem:\r\n    def __init__(self, model, color, cost):\r\n        self.__model = model\r\n        self.__color = color\r\n        self.__cost = cost\r\n\r\n    def get_model(self):\r\n        return self.__model\r\n\r\n    def get_color(self):\r\n        return self.__color\r\n\r\n    def set_color(self, color):\r\n        self.__color = color\r\n\r\n    def get_cost(self):\r\n        return self.__cost\r\n\r\n    def set_cost(self, cost):\r\n        self.__cost = cost\r\n\r\n\r\nclass Shoes(SportsItem):\r\n    def __init__(self, model, color, cost, brand):\r\n        super().__init__(model, color, cost)\r\n        self.__brand = brand\r\n\r\n    def info(self):\r\n        return (self.get_model() + \" of brand \" + self.__brand + \" in \"\r\n                + self.get_color() + \" color for Rs.\" + str(self.get_cost()))\r\n\r\n\r\nsh1 = Shoes(\"Shoes\", \"Black\", 3699, \"Xyz123\")\r\nprint(sh1.info())\r\nprint(sh1.get_model())\r\nsh2 = Shoes(\"Shoes\", \"Black red\", 4599, \"Xyz345\")\r\nprint(sh2.info())\r\nsh2.set_cost(3999)\r\nprint(sh2.info())\r\n\r\n# 3. Private name from a child\r\nclass BadShoes(SportsItem):\r\n    def show(self):\r\n        return self.__model\r\n\r\ntry:\r\n    BadShoes(\"Shoes\", \"Black\", 3699).show()\r\nexcept AttributeError as e:\r\n    print(\"AttributeError:\", e)\r\n\r\n# 4. Forgetting super().__init__\r\nclass ForgetfulShoes(SportsItem):\r\n    def __init__(self, brand):\r\n        self.brand = brand\r\n\r\ntry:\r\n    ForgetfulShoes(\"Xyz\").get_model()\r\nexcept AttributeError as e:\r\n    print(\"AttributeError:\", e)\r\n\r\n# 5. Overriding and super()\r\nclass Animal:\r\n    def speak(self):\r\n        return \"Some sound\"\r\n\r\nclass Dog(Animal):\r\n    def speak(self):\r\n        return super().speak() + \", then Woof\"\r\n\r\nprint(Animal().speak())\r\nprint(Dog().speak())\r\n\r\n# 6. isinstance and issubclass\r\nd = Dog()\r\nprint(isinstance(d, Dog), isinstance(d, Animal), isinstance(Animal(), Dog))\r\nprint(issubclass(Dog, Animal), issubclass(Animal, Dog))\r\n\r\n# 7. Types\r\nclass A:\r\n    def who(self):\r\n        return \"A\"\r\n\r\nclass B(A):\r\n    pass\r\n\r\nclass C(B):\r\n    pass\r\n\r\nprint(C().who())\r\nprint([k.__name__ for k in C.__mro__])\r\n\r\nclass Shape:\r\n    def area(self):\r\n        return 0\r\n\r\nclass Square(Shape):\r\n    def __init__(self, s):\r\n        self.s = s\r\n    def area(self):\r\n        return self.s * self.s\r\n\r\nclass Circle(Shape):\r\n    def __init__(self, r):\r\n        self.r = r\r\n    def area(self):\r\n        return round(3.14159 * self.r * self.r, 2)\r\n\r\nfor sh in (Square(4), Circle(3)):\r\n    print(type(sh).__name__, sh.area())\r\n\r\nclass Base:\r\n    def hello(self):\r\n        return \"Base\"\r\n\r\nclass Left(Base):\r\n    def hello(self):\r\n        return \"Left then \" + super().hello()\r\n\r\nclass Right(Base):\r\n    def hello(self):\r\n        return \"Right then \" + super().hello()\r\n\r\nclass Bottom(Left, Right):\r\n    def hello(self):\r\n        return \"Bottom then \" + super().hello()\r\n\r\nprint(Bottom().hello())\r\nprint([k.__name__ for k in Bottom.__mro__])\r\n\r\n# 8. Multiple inheritance\r\nclass Super1:\r\n    def __init__(self):\r\n        self.test1 = \"Python\"\r\n        print(\"Superclass1\")\r\n\r\nclass Super2:\r\n    def __init__(self):\r\n        self.test2 = \"Tutorials\"\r\n        print(\"Superclass2\")\r\n\r\nclass MultiInher(Super1, Super2):\r\n    def __init__(self):\r\n        Super1.__init__(self)\r\n        Super2.__init__(self)\r\n        print(\"Derived\")\r\n\r\n    def print_vals(self):\r\n        print(self.test1, self.test2)\r\n\r\nobj = MultiInher()\r\nobj.print_vals()\r\n\r\n# 9. Composition\r\nclass Engine:\r\n    def start(self):\r\n        return \"Engine started\"\r\n\r\nclass Car:\r\n    def __init__(self):\r\n        self.engine = Engine()\r\n    def start(self):\r\n        return self.engine.start()\r\n\r\nprint(Car().start())\r\n\r\n# 10. Unindented code\r\ntry:\r\n    compile(\"class X:\\ndef f(self):\\n    pass\", \"x\", \"exec\")\r\nexcept IndentationError as e:\r\n    print(\"IndentationError:\", e.msg)\r\n\r\nprint(sys.version_info[:2])<\/pre>\n<\/div>\n<p><iframe loading=\"lazy\" src=\"https:\/\/www.youtube.com\/embed\/QjYfZk6IQCc\" width=\"850\" height=\"315\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n<p>Inheritance saves the most when the parent is small and clear, and the children change only a little. Start with single inheritance and super(), and add the other types only when a real problem calls for them. Type the examples, break them on purpose, and read the errors. A good next step is to learn about abstract classes and polymorphism, which build on what you learned here.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python Inheritance Tutorial: Types, super() and Examples Imagine you are writing a program for a sports shop. You write a class for sports items with a model, a colour and a cost. Next, you need a class for shoes, which has all of those and a brand as well. Do you copy the first class [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3387,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,1679],"tags":[539,546,542,74],"class_list":["post-2660","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-python-oops","tag-online-course-on-python","tag-online-python-programming-course","tag-online-python-training-course","tag-python-inheritance-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Inheritance Tutorial: Types, super() and Examples<\/title>\n<meta name=\"description\" content=\"Learn inheritance in Python with tested code: parent and child classes, super(), overriding, all five types, MRO, and the errors to avoid. By PrwaTech\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Inheritance Tutorial: Types, super() and Examples\" \/>\n<meta property=\"og:description\" content=\"Learn inheritance in Python with tested code: parent and child classes, super(), overriding, all five types, MRO, and the errors to avoid. By PrwaTech\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-20T11:14:38+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-22T02:26:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/07\/Python-Inheritance-Tutorial.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/\",\"url\":\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/\",\"name\":\"Python Inheritance Tutorial: Types, super() and Examples\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/07\/Python-Inheritance-Tutorial.jpg\",\"datePublished\":\"2026-10-20T11:14:38+00:00\",\"dateModified\":\"2026-10-22T02:26:18+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Learn inheritance in Python with tested code: parent and child classes, super(), overriding, all five types, MRO, and the errors to avoid. By PrwaTech\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/07\/Python-Inheritance-Tutorial.jpg\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/07\/Python-Inheritance-Tutorial.jpg\",\"width\":960,\"height\":550,\"caption\":\"Python Inheritance Tutorial\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Inheritance Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Inheritance Tutorial: Types, super() and Examples","description":"Learn inheritance in Python with tested code: parent and child classes, super(), overriding, all five types, MRO, and the errors to avoid. By PrwaTech","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:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Python Inheritance Tutorial: Types, super() and Examples","og_description":"Learn inheritance in Python with tested code: parent and child classes, super(), overriding, all five types, MRO, and the errors to avoid. By PrwaTech","og_url":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2026-10-20T11:14:38+00:00","article_modified_time":"2026-10-22T02:26:18+00:00","og_image":[{"width":960,"height":550,"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/07\/Python-Inheritance-Tutorial.jpg","type":"image\/jpeg"}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/","url":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/","name":"Python Inheritance Tutorial: Types, super() and Examples","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/07\/Python-Inheritance-Tutorial.jpg","datePublished":"2026-10-20T11:14:38+00:00","dateModified":"2026-10-22T02:26:18+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Learn inheritance in Python with tested code: parent and child classes, super(), overriding, all five types, MRO, and the errors to avoid. By PrwaTech","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/07\/Python-Inheritance-Tutorial.jpg","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/07\/Python-Inheritance-Tutorial.jpg","width":960,"height":550,"caption":"Python Inheritance Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/python\/python-oops\/python-inheritance-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Python Inheritance Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=2660"}],"version-history":[{"count":16,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2660\/revisions"}],"predecessor-version":[{"id":12073,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2660\/revisions\/12073"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media\/3387"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=2660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=2660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=2660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}