{"id":240,"date":"2019-03-04T01:00:08","date_gmt":"2019-03-04T01:00:08","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/python\/?p=240"},"modified":"2019-03-05T11:43:14","modified_gmt":"2019-03-05T11:43:14","slug":"python-object-oriented-programming","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/","title":{"rendered":"Python &#8211; Object Oriented Programming"},"content":{"rendered":"<p>In this chapter, we are going to use Object Oriented Programming(OOP) features of Python. You will become an expert in Python OOP.<\/p>\n<p>So we&#8217;ll cover the following<\/p>\n<ol>\n<li><a href=\"#t1\">Review of OOP Terms<\/a><\/li>\n<li><a href=\"#t2\">Creating a Class<\/a><\/li>\n<li><a href=\"#t3\">Creating Objects from a Class<\/a><\/li>\n<li><a href=\"#t4\">Accessing Attributes<\/a><\/li>\n<li><a href=\"#t5\">Built-in Class Attributes<\/a><\/li>\n<li><a href=\"#t6\">Garbage Collection in Python<\/a><\/li>\n<li><a href=\"#t7\">Inheritance in Python<\/a><\/li>\n<li><a href=\"#t8\">Base Overloading Methods<\/a><\/li>\n<li><a href=\"#t9\">Operator Overloading<\/a><\/li>\n<li><a href=\"#t10\">Data Hiding<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Review of OOP Terms<\/strong><\/h4>\n<p>Let&#8217;s reviews some of the important OOP terms.<\/p>\n<p><strong>Class<\/strong> &#8211; A blueprint for creating new object. A class defines the attributes and behaviors of an object. The attributes are data members (instance and class variables). The behavior is represented by methods(or member functions)<\/p>\n<p><strong>Class Variable<\/strong> &#8211; This is a variable that is shared by all objects created from the class. You define class variables inside the class but outside any of the methods.<\/p>\n<p><strong>Data Member<\/strong> &#8211; This are variables defined in the class. They are used to hold data associated with the specific class<\/p>\n<p><strong>Function Overloading<\/strong> &#8211; You use function overloading to create two functions with same name. But they perform different operations based on its arguments<\/p>\n<p><strong>Instance Variable<\/strong> &#8211; These is a variable that is defined in a class but belongs only to the particular instance of the class.<\/p>\n<p><strong>Instance<\/strong> &#8211; An object created from a class<\/p>\n<p><strong>Inheritance<\/strong> &#8211; The feature that allows a class to inherit the properties of another class. The parent class is called the super class while the child class is called sub class.<\/p>\n<p><strong>Instantiation<\/strong> &#8211; The process of creating an instance (object of a class)<\/p>\n<p><strong>Operator Overloading<\/strong> &#8211; The process where an operator performs more than one type of operation<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Creating a Class<\/strong><\/h4>\n<p>You create a class using the class statement<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"background-color: #fff0f0;\">'Creating an new Class'<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">Student<\/span>:\r\n   <span style=\"background-color: #fff0f0;\">'Common base class for all students'<\/span>\r\n   noOfStudents <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">__init__<\/span>(<span style=\"color: #007020;\">self<\/span>, regno, firstname, lastname):\r\n      <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>regno <span style=\"color: #333333;\">=<\/span> regno\r\n      <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>firstname <span style=\"color: #333333;\">=<\/span> firstname\r\n      <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>lastname <span style=\"color: #333333;\">=<\/span> lastname\r\n      Student<span style=\"color: #333333;\">.<\/span>noOfStudents <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">displayCount<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n     <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Total Students %d\"<\/span> <span style=\"color: #333333;\">%<\/span> Student<span style=\"color: #333333;\">.<\/span>noOfStudents)\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">printStudent<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n      <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Reg. Number: \"<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>regno, <span style=\"background-color: #fff0f0;\">\"Name: \"<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>firstname <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" \"<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>lastname)\r\n<\/pre>\n<p>Listing 1.0: Definition of the Student Class<\/p>\n<p>&nbsp;<\/p>\n<p>Let&#8217;s understand some parts of this class definition<\/p>\n<p>noOfStudents:\u00a0 this is a class variable. Therefore it belongs to the class. It&#8217;s value is shared by all objects created from this class. You can access it using the class name. For example, <em>Student.noOfStudents<\/em>. Also, just one copy\u00a0 exist in memory.<\/p>\n<p>__init__ (): This is a special function. It is called a constructor. It is called when the class is instantiated.<\/p>\n<p>self: this refers to the current class<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Creating Objects from a Class (Instantiation)<\/strong><\/h4>\n<p>Now that we have our class defined, we can then create objects from the class. To do this, you call the class using its name. Then you pass the arguments as defined in the __init__ function.<\/p>\n<p>For example, we create and display two student objects<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">student1  <span style=\"color: #333333;\">=<\/span> Student(<span style=\"background-color: #fff0f0;\">\"001\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Solace\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Okeke\"<\/span>)\r\nstudent2  <span style=\"color: #333333;\">=<\/span> Student(<span style=\"background-color: #fff0f0;\">\"002\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Treasure\"<\/span>, <span style=\"background-color: #fff0f0;\">\"Munonye\"<\/span>)\r\n\r\nstudent1<span style=\"color: #333333;\">.<\/span>printStudent()\r\nstudent2<span style=\"color: #333333;\">.<\/span>printStudent()\r\n\r\n<span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Number of Students: %d\"<\/span> <span style=\"color: #333333;\">%<\/span>(Student<span style=\"color: #333333;\">.<\/span>noOfStudents))\r\n<\/pre>\n<p>Listing 1.1: Creating objects and accessing attributes<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Accessing Attributes<\/strong><\/h4>\n<p>You can notice that in the Listing 1.1 above, we create two objects, student1 and student2. Then we access the attributes printStudent() and noOfStuents.<\/p>\n<p>But you can also use certain functions defined in Python to access attributes. These functions are given in the table below.<\/p>\n<table style=\"width: 100%;\" align=\"center\">\n<tbody>\n<tr>\n<td><strong>getattr(object, name):<\/strong> used to access the attribute of the object<\/td>\n<\/tr>\n<tr>\n<td><strong>hasattr(object, name):<\/strong> used to check if an attribute exists<\/td>\n<\/tr>\n<tr>\n<td><strong>setattr(object, name, value):<\/strong> assigns an attribute. If the attribute does not exits, then\u00a0 it is created<\/td>\n<\/tr>\n<tr>\n<td><strong>delattr(object, name):<\/strong> deletes an attribute<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007020;\">hasattr<\/span>(student1, <span style=\"background-color: #fff0f0;\">'grade'<\/span>)                  <span style=\"color: #888888;\"># returns False<\/span>\r\n<span style=\"color: #007020;\">getattr<\/span>(student1, <span style=\"background-color: #fff0f0;\">'firstname'<\/span>)              <span style=\"color: #888888;\"># returns Solace<\/span>\r\n\r\n<span style=\"color: #007020;\">setattr<\/span>(student1, <span style=\"background-color: #fff0f0;\">'firstname'<\/span>, <span style=\"background-color: #fff0f0;\">'Oleander'<\/span>)  <span style=\"color: #888888;\"># changes the lastname to Oleander<\/span>\r\n\r\n<span style=\"color: #007020;\">delattr<\/span>(student1, <span style=\"background-color: #fff0f0;\">'lastname'<\/span>)               <span style=\"color: #888888;\"># deletes the lastname attribute<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Built-in Class Attribute<\/strong><\/h4>\n<p>Python provides some built-in attributes that you can use for certain operation. Just like normal attributes, these built-in attributes can be accessed the same way.<\/p>\n<ul class=\"list\">\n<li><b>__dict__<\/b>\u00a0: Dictionary that contains the class&#8217;s namespace.<\/li>\n<li><b>__doc__<\/b>\u00a0:\u00a0 The Class documentation string or none, if undefined.<\/li>\n<li><b>__name__<\/b>\u00a0: The name of the Class<\/li>\n<li><b>__module__<\/b>\u00a0:\u00a0 Name of the module where the class is defined. This attribute is &#8220;__main__&#8221; in interactive mode.<\/li>\n<li><b>__bases__<\/b>\u00a0:\u00a0 A tuple that contains the base classes. Listed in the order of their occurrence in the base class list.<\/li>\n<\/ul>\n<p>We now used these in-built attributes for the Student class\u2212<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"background-color: #fff0f0;\">'Creating an new Class'<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">Student<\/span>:\r\n   <span style=\"background-color: #fff0f0;\">'Common base class for all students'<\/span>\r\n   noOfStudents <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">__init__<\/span>(<span style=\"color: #007020;\">self<\/span>, regno, firstname, lastname):\r\n      <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>regno <span style=\"color: #333333;\">=<\/span> regno\r\n      <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>firstname <span style=\"color: #333333;\">=<\/span> firstname\r\n      <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>lastname <span style=\"color: #333333;\">=<\/span> lastname\r\n      Student<span style=\"color: #333333;\">.<\/span>noOfStudents <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">displayCount<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n     <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Total Students %d\"<\/span> <span style=\"color: #333333;\">%<\/span> Student<span style=\"color: #333333;\">.<\/span>noOfStudents)\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">printStudent<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n      <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Reg. Number: \"<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>regno, <span style=\"background-color: #fff0f0;\">\"Name: \"<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>firstname <span style=\"color: #333333;\">+<\/span> <span style=\"background-color: #fff0f0;\">\" \"<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>lastname)\r\n\r\n\r\n<span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Student.__doc__:\"<\/span>, Student<span style=\"color: #333333;\">.<\/span>__doc__)\r\n<span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Student.__name__:\"<\/span>, Student<span style=\"color: #333333;\">.<\/span>__name__)\r\n<span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Student.__module__:\"<\/span>, Student<span style=\"color: #333333;\">.<\/span>__module__)\r\n<span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Student.__bases__:\"<\/span>, Student<span style=\"color: #333333;\">.<\/span>__bases__)\r\n<span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Student.__dict__:\"<\/span>, Student<span style=\"color: #333333;\">.<\/span>__dict__)\r\n<\/pre>\n<p>Listing 1.2: Using inbuilt attributes<\/p>\n<p>&nbsp;<\/p>\n<p>If you run the code in Listing 1.2, you will have the following output<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">Student<span style=\"color: #333333;\">.<\/span>__doc__: Common base <span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">for<\/span> <span style=\"color: #007020;\">all<\/span> students\r\nStudent<span style=\"color: #333333;\">.<\/span>__name__: Student\r\nStudent<span style=\"color: #333333;\">.<\/span>__module__: __main__\r\nStudent<span style=\"color: #333333;\">.<\/span>__bases__: (<span style=\"color: #333333;\">&lt;<\/span><span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #ff0000; background-color: #ffaaaa;\">'<\/span><span style=\"color: #bb0066; font-weight: bold;\">object<\/span><span style=\"background-color: #fff0f0;\">'&gt;,)<\/span>\r\nStudent<span style=\"color: #333333;\">.<\/span>__dict__: {<span style=\"background-color: #fff0f0;\">'__module__'<\/span>: <span style=\"background-color: #fff0f0;\">'__main__'<\/span>, <span style=\"background-color: #fff0f0;\">'__doc__'<\/span>: <span style=\"background-color: #fff0f0;\">'Common base class for all students'<\/span>, <span style=\"background-color: #fff0f0;\">'noOfStudents'<\/span>: <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>, <span style=\"background-color: #fff0f0;\">'__init__'<\/span>: <span style=\"color: #333333;\">&lt;<\/span>function Student<span style=\"color: #333333;\">.<\/span>__init__ at <span style=\"color: #005588; font-weight: bold;\">0x000001B37FF81E18<\/span><span style=\"color: #333333;\">&gt;<\/span>, <span style=\"background-color: #fff0f0;\">'displayCount'<\/span>: <span style=\"color: #333333;\">&lt;<\/span>function Student<span style=\"color: #333333;\">.<\/span>displayCount at <span style=\"color: #005588; font-weight: bold;\">0x000001B37FF81F28<\/span><span style=\"color: #333333;\">&gt;<\/span>, <span style=\"background-color: #fff0f0;\">'printStudent'<\/span>: <span style=\"color: #333333;\">&lt;<\/span>function Student<span style=\"color: #333333;\">.<\/span>printStudent at <span style=\"color: #005588; font-weight: bold;\">0x000001B37FF892F0<\/span><span style=\"color: #333333;\">&gt;<\/span>, <span style=\"background-color: #fff0f0;\">'__dict__'<\/span>: <span style=\"color: #333333;\">&lt;<\/span>attribute <span style=\"background-color: #fff0f0;\">'__dict__'<\/span> of <span style=\"background-color: #fff0f0;\">'Student'<\/span> objects<span style=\"color: #333333;\">&gt;<\/span>, <span style=\"background-color: #fff0f0;\">'__weakref__'<\/span>: <span style=\"color: #333333;\">&lt;<\/span>attribute <span style=\"background-color: #fff0f0;\">'__weakref__'<\/span> of <span style=\"background-color: #fff0f0;\">'Student'<\/span> objects<span style=\"color: #333333;\">&gt;<\/span>}\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t6\">6. Garbage Collection in Python<\/strong><\/h4>\n<p>Python uses automatic garbage collection. This means that unneccessary objects are deleted automatically by the Python interpreter. Therefore, memory is freed by reclaiming unused memory blocks.<\/p>\n<p>The Python garbage collector starts running as soon as program execution starts but is actually triggered when no more references to the object. So we can say that the object&#8217;s reference count is zero.<\/p>\n<p>An object reference count increases when it is place in a collection or assigned a new name. Similarly, the object reference count decreases when it&#8217;s deleted with the del command or its reference is reassigned or it goes out of scope.<\/p>\n<p>How it works is illustrated below:<\/p>\n<pre class=\"result notranslate\">x = 20      # Create object &lt;20&gt;\r\ny = a       # Increase reference count  of &lt;20&gt; \r\nz = [b]     # Increase reference count  of &lt;20&gt; \r\n\r\ndel x       # Decrease reference. count  of &lt;20&gt;\r\ny = 100     # Decrease reference count  of &lt;20&gt; \r\nz[0] = -1   # Decrease reference count  of &lt;20&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t7\">7. Inheritance in Python<\/strong><\/h4>\n<p>As you know, inheritance allows you to create a class that inherits from an existing class. You do this by placing the existing class name in brackets after the new class name.<\/p>\n<p>If you do this, then you can use the attributes of the parent class in the child class. The code below illustrates this:<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">Parent<\/span>:        <span style=\"color: #888888;\"># define the parent class<\/span>\r\n   parentAttr <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">100<\/span>\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">__init__<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n      <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"This is the parent constructor\"<\/span>)\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">parentMethod<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n      <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'This is a parent method'<\/span>)\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">setAttr<\/span>(<span style=\"color: #007020;\">self<\/span>, attr):\r\n      Parent<span style=\"color: #333333;\">.<\/span>parentAttr <span style=\"color: #333333;\">=<\/span> attr\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">getAttr<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n      <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"Parent attribute :\"<\/span>, Parent<span style=\"color: #333333;\">.<\/span>parentAttr)\r\n\r\n<span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">Child<\/span>(Parent): <span style=\"color: #888888;\"># define the child class, inherits Parent<\/span>\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">__init__<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n      <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">\"This is the child constructor\"<\/span>)\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">childMethod<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n      <span style=\"color: #007020;\">print<\/span>(<span style=\"background-color: #fff0f0;\">'This is a child method'<\/span>)\r\n\r\nchild1 <span style=\"color: #333333;\">=<\/span> Child()          <span style=\"color: #888888;\"># Create an instance of child<\/span>\r\nchild1<span style=\"color: #333333;\">.<\/span>childMethod()      <span style=\"color: #888888;\"># Child calls its own method<\/span>\r\nchild1<span style=\"color: #333333;\">.<\/span>parentMethod()     <span style=\"color: #888888;\"># Child calls inherited parent's method<\/span>\r\nchild1<span style=\"color: #333333;\">.<\/span>setAttr(<span style=\"color: #0000dd; font-weight: bold;\">100<\/span>)       <span style=\"color: #888888;\"># Child calls inherited parent's method<\/span>\r\nchild1<span style=\"color: #333333;\">.<\/span>getAttr()          <span style=\"color: #888888;\"># Child also calls inherited parent's method<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>The output of running this code is given below<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">This <span style=\"color: #000000; font-weight: bold;\">is<\/span> the child constructor\r\nThis <span style=\"color: #000000; font-weight: bold;\">is<\/span> a child method\r\nThis <span style=\"color: #000000; font-weight: bold;\">is<\/span> a parent method\r\nParent attribute : <span style=\"color: #0000dd; font-weight: bold;\">100<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Multiple Inheritance in Python<\/strong><\/p>\n<p>Unlike Java, Python supports multiple inheritance. Hence a class can inherit from two or more parents.<\/p>\n<p>To achieve this, simply place the names of the parents in brackets separated by commas. For example, Child in the code below inherits from three parents<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">Child<\/span>(Parent1, Parent2, Parent3)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>issubclass() and isinstance()<\/strong><\/p>\n<p>The issubclass() method is used to check if a given class is a subclass of\u00a0 another class<\/p>\n<p>The isinstance() method is used to check if an object is an instance of a given class.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Overriding Methods<\/strong><\/p>\n<p>Overriding occurs when there is a method in the parent and child class that have the same name. In this case,\u00a0 the method in the child class overrides the method in the parent class. You probably would need to override sometimes to improve the functionality of the method.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t8\">8. Base Overloading Methods<\/strong><\/h4>\n<p>There are some built-in method that you can always override in your class. These methods are given in the table below.<\/p>\n<table class=\"table table-bordered\" style=\"width: 100%;\" align=\"center\">\n<tbody>\n<tr>\n<th>SN<\/th>\n<th>Method and description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>__init__ ( self [,args&#8230;] )<\/b><\/p>\n<p>Constructor (with any optional arguments)<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>__del__( self )<\/b><\/p>\n<p>Destructor, deletes an object<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>__repr__( self )<\/b><\/p>\n<p>Evaluable string representation<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>__str__( self )<\/b><\/p>\n<p>Printable string representation<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>__cmp__ ( self, x )<\/b><\/p>\n<p>Object comparison<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t9\">9. Operator Overloading<\/strong><\/h4>\n<p>As you know, you can define an operator to have more than on functionality. For example, the addition operator(+) add two numbers. However, it would not add two vectors. If you try to use it to add two vectors, then you receive an error.<\/p>\n<p>So to solve this problem, you overload the addition operator(+). You define it to also perform addition on vectors.Simply define the __add__ method in your class.<\/p>\n<p>The code is given below. I recommend you try it yourself. Also remember to watch the video.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">Vector<\/span>:\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">__init__<\/span>(<span style=\"color: #007020;\">self<\/span>, x, y):\r\n      <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>x <span style=\"color: #333333;\">=<\/span> x\r\n      <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>y <span style=\"color: #333333;\">=<\/span> y\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">__str__<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n      <span style=\"color: #008800; font-weight: bold;\">return<\/span> <span style=\"background-color: #fff0f0;\">'Vector (%d, %d)'<\/span> <span style=\"color: #333333;\">%<\/span> (<span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>x, <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>y)\r\n\r\n   <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">__add__<\/span>(<span style=\"color: #007020;\">self<\/span>, vec):\r\n      <span style=\"color: #008800; font-weight: bold;\">return<\/span> Vector(<span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>x <span style=\"color: #333333;\">+<\/span> vec<span style=\"color: #333333;\">.<\/span>x, <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>y <span style=\"color: #333333;\">+<\/span> vec<span style=\"color: #333333;\">.<\/span>y)\r\n\r\nvector1 <span style=\"color: #333333;\">=<\/span> Vector(<span style=\"color: #0000dd; font-weight: bold;\">5<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">20<\/span>)\r\nvector2 <span style=\"color: #333333;\">=<\/span> Vector(<span style=\"color: #0000dd; font-weight: bold;\">2<\/span>,<span style=\"color: #0000dd; font-weight: bold;\">10<\/span>)\r\n<span style=\"color: #007020;\">print<\/span>(vector1 <span style=\"color: #333333;\">+<\/span> vector2)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t10\">10. Data Hiding in Python<\/strong><\/h4>\n<p>Simply put, data hiding an OOP concept used to hide internal details of a class(attributes, for example).<\/p>\n<p>As such, the attribute is not visible outside the class definition.\u00a0 To achieve this, you will have to name the attribute with double underscore.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">class<\/span> <span style=\"color: #bb0066; font-weight: bold;\">Employee<\/span>:\r\n    __empCount <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">0<\/span>\r\n\r\n    <span style=\"color: #008800; font-weight: bold;\">def<\/span> <span style=\"color: #0066bb; font-weight: bold;\">count<\/span>(<span style=\"color: #007020;\">self<\/span>):\r\n        <span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>__empCount <span style=\"color: #333333;\">+=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">1<\/span>\r\n        <span style=\"color: #007020;\">print<\/span>(<span style=\"color: #007020;\">self<\/span><span style=\"color: #333333;\">.<\/span>__empCount)\r\n\r\nemployee1 <span style=\"color: #333333;\">=<\/span> Employee()\r\nemployee1<span style=\"color: #333333;\">.<\/span>count()\r\nemployee1<span style=\"color: #333333;\">.<\/span>count()\r\n\r\n<span style=\"color: #007020;\">print<\/span>(employee1<span style=\"color: #333333;\">.<\/span>__empCount)  <span style=\"color: #888888;\"># This would yeild error<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>When you execute the code above, you will get an error.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this chapter, we are going to use Object Oriented Programming(OOP) features of Python. You will become an expert in Python OOP. So we&#8217;ll cover &hellip; <\/p>\n","protected":false},"author":395,"featured_media":241,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-240","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python - Object Oriented Programming - Python Tutorials<\/title>\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.kindsonthegenius.com\/python\/python-object-oriented-programming\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python - Object Oriented Programming - Python Tutorials\" \/>\n<meta property=\"og:description\" content=\"In this chapter, we are going to use Object Oriented Programming(OOP) features of Python. You will become an expert in Python OOP. So we&#8217;ll cover &hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-04T01:00:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-05T11:43:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Object-Oriented-Programming-With-Python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"934\" \/>\n\t<meta property=\"og:image:height\" content=\"520\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\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\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"headline\":\"Python &#8211; Object Oriented Programming\",\"datePublished\":\"2019-03-04T01:00:08+00:00\",\"dateModified\":\"2019-03-05T11:43:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/\"},\"wordCount\":1180,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/wp-content\\\/uploads\\\/sites\\\/8\\\/2019\\\/03\\\/Object-Oriented-Programming-With-Python.jpg\",\"articleSection\":[\"Python Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/\",\"name\":\"Python - Object Oriented Programming - Python Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/wp-content\\\/uploads\\\/sites\\\/8\\\/2019\\\/03\\\/Object-Oriented-Programming-With-Python.jpg\",\"datePublished\":\"2019-03-04T01:00:08+00:00\",\"dateModified\":\"2019-03-05T11:43:14+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/wp-content\\\/uploads\\\/sites\\\/8\\\/2019\\\/03\\\/Object-Oriented-Programming-With-Python.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/wp-content\\\/uploads\\\/sites\\\/8\\\/2019\\\/03\\\/Object-Oriented-Programming-With-Python.jpg\",\"width\":934,\"height\":520},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/python-object-oriented-programming\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python &#8211; Object Oriented Programming\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/\",\"name\":\"Python Tutorials\",\"description\":\"Python Tutorial for Programming and Data Science\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/python\\\/author\\\/kindsonthegenius-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python - Object Oriented Programming - Python Tutorials","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.kindsonthegenius.com\/python\/python-object-oriented-programming\/","og_locale":"en_US","og_type":"article","og_title":"Python - Object Oriented Programming - Python Tutorials","og_description":"In this chapter, we are going to use Object Oriented Programming(OOP) features of Python. You will become an expert in Python OOP. So we&#8217;ll cover &hellip;","og_url":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/","og_site_name":"Python Tutorials","article_published_time":"2019-03-04T01:00:08+00:00","article_modified_time":"2019-03-05T11:43:14+00:00","og_image":[{"width":934,"height":520,"url":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Object-Oriented-Programming-With-Python.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/python\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"headline":"Python &#8211; Object Oriented Programming","datePublished":"2019-03-04T01:00:08+00:00","dateModified":"2019-03-05T11:43:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/"},"wordCount":1180,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Object-Oriented-Programming-With-Python.jpg","articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/","url":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/","name":"Python - Object Oriented Programming - Python Tutorials","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Object-Oriented-Programming-With-Python.jpg","datePublished":"2019-03-04T01:00:08+00:00","dateModified":"2019-03-05T11:43:14+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Object-Oriented-Programming-With-Python.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/python\/wp-content\/uploads\/sites\/8\/2019\/03\/Object-Oriented-Programming-With-Python.jpg","width":934,"height":520},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/python\/python-object-oriented-programming\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/python\/"},{"@type":"ListItem","position":2,"name":"Python &#8211; Object Oriented Programming"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/python\/#website","url":"https:\/\/www.kindsonthegenius.com\/python\/","name":"Python Tutorials","description":"Python Tutorial for Programming and Data Science","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/python\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/python\/author\/kindsonthegenius-2\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/240","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/comments?post=240"}],"version-history":[{"count":5,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/240\/revisions"}],"predecessor-version":[{"id":246,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/posts\/240\/revisions\/246"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/media\/241"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/media?parent=240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/categories?post=240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/python\/wp-json\/wp\/v2\/tags?post=240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}