{"id":47857,"date":"2021-10-25T06:09:47","date_gmt":"2021-10-25T00:39:47","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/"},"modified":"2026-05-28T15:01:14","modified_gmt":"2026-05-28T09:31:14","slug":"oops-concepts-in-python","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/","title":{"rendered":"OOPs Concepts in Python"},"content":{"rendered":"\n<p><strong>Object-Oriented Programming (OOP)<\/strong> is a way of organizing your code. It lets you create programs that are easy to understand and manage. In Python, OOP uses \"objects\" to represent real-world things or ideas. These objects combine data and the actions that can be performed on that data.<\/p>\n\n\n\n<p>Using OOP helps you write code that is reusable and flexible. You can build complex systems by breaking them into smaller, manageable parts. This makes your programs easier to update and fix over time.<\/p>\n\n\n\n<p>Here are the main concepts in Python OOP:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Classes<\/strong><\/li>\n\n\n\n<li><strong>Objects<\/strong><\/li>\n\n\n\n<li><strong>Inheritance<\/strong><\/li>\n\n\n\n<li><strong>Encapsulation<\/strong><\/li>\n\n\n\n<li><strong>Polymorphism<\/strong><\/li>\n\n\n\n<li><strong>Abstraction<\/strong><\/li>\n<\/ul>\n\n\n\n<p>You can use these concepts to write better Python code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"1-classes\">1. Classes<\/h2>\n\n\n\n<p>A <strong>class<\/strong> is like a blueprint or a template. It defines a set of rules for creating objects. Think of a class as the design for a house. The design tells you what the house will have: how many rooms, where the windows are, and so on.<\/p>\n\n\n\n<p>A class in Python defines:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Attributes:<\/strong> These are the data or properties that objects of this class will have. For a <code>Car<\/code> class, attributes might be <code>color<\/code>, <code>make<\/code>, or <code>model<\/code>.<\/li>\n\n\n\n<li><strong>Methods:<\/strong> These are the functions or actions that objects of this class can perform. For a <code>Car<\/code> class, methods might be <code>start_engine()<\/code>, <code>drive()<\/code>, or <code>stop()<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>You create a class using the <code>class<\/code> keyword.<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb9517\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code><span class=\"kw\">class<\/span> Car:\n    <span class=\"cm\"># This is an attribute common to all cars<\/span>\n    wheels = <span class=\"nm\">4<\/span>\n\n    <span class=\"cm\"># This is a special method called a constructor.<\/span>\n    <span class=\"cm\"># It runs when you create a new Car object.<\/span>\n    <span class=\"kw\">def<\/span> <span class=\"fn\">__init__<\/span>(self, make, model, color):\n        self.make = make      <span class=\"cm\"># Instance attribute<\/span>\n        self.model = model    <span class=\"cm\"># Instance attribute<\/span>\n        self.color = color    <span class=\"cm\"># Instance attribute<\/span>\n\n    <span class=\"cm\"># This is a method (an action the car can do)<\/span>\n    <span class=\"kw\">def<\/span> <span class=\"fn\">drive<\/span>(self):\n        <span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;The {self.color} {self.make} {self.model} is driving.&quot;<\/span>)<\/code><\/pre><\/div>\n\n\n\n<p>In this <code>Car<\/code> class, <code>wheels<\/code> is a class attribute. <code>make<\/code>, <code>model<\/code>, and <code>color<\/code> are instance attributes. The <code>drive()<\/code> method lets a car object perform an action.<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-objects\">2. Objects<\/h2>\n\n\n\n<p>An <strong>object<\/strong> is a real instance of a class. If a class is a blueprint for a house, an object is an actual house built from that blueprint. You can build many houses from one design, and each house is an object.<\/p>\n\n\n\n<p>Each object has its own unique set of data based on the class's attributes.<\/p>\n\n\n\n<p>You create an object by calling the class name like a function.<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb959d\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code><span class=\"cm\"># Create an object (an instance) of the Car class<\/span>\nmy_car = <span class=\"fn\">Car<\/span>(<span class=\"st\">&quot;Toyota&quot;<\/span>, <span class=\"st\">&quot;Camry&quot;<\/span>, <span class=\"st\">&quot;blue&quot;<\/span>)\nyour_car = <span class=\"fn\">Car<\/span>(<span class=\"st\">&quot;Honda&quot;<\/span>, <span class=\"st\">&quot;Civic&quot;<\/span>, <span class=\"st\">&quot;red&quot;<\/span>)\n\n<span class=\"cm\"># Access attributes of the objects<\/span>\n<span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;My car is a {my_car.color} {my_car.make} {my_car.model}.&quot;<\/span>)\n<span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;Your car has {your_car.wheels} wheels.&quot;<\/span>)\n\n<span class=\"cm\"># Call methods on the objects<\/span>\nmy_car.<span class=\"fn\">drive<\/span>()\nyour_car.<span class=\"fn\">drive<\/span>()<\/code><\/pre><\/div>\n\n\n\n<p>This code outputs:<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb95ac\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>My car is a blue Toyota Camry.\nYour car has <span class=\"nm\">4<\/span> wheels.\nThe blue Toyota Camry is driving.\nThe red Honda Civic is driving.<\/code><\/pre><\/div>\n\n\n\n<p><code>my_car<\/code> and <code>your_car<\/code> are two different objects. They use the same <code>Car<\/code> blueprint but have their own specific color, make, and model.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-inheritance\">3. Inheritance<\/h2>\n\n\n\n<p><strong>Inheritance<\/strong> lets you create a new class from an existing class. The new class, called the \"child class\" or \"derived class,\" gets all the attributes and methods of the original class, called the \"parent class\" or \"base class.\"<\/p>\n\n\n\n<p>This helps you reuse code. You do not have to write the same code again. You can also add new features or change existing ones in the child class.<\/p>\n\n\n\n<p>Think of a <code>Vehicle<\/code> class as a parent. A <code>Car<\/code> class and a <code>Motorcycle<\/code> class can inherit from <code>Vehicle<\/code>. Both cars and motorcycles are vehicles.<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb960e\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code><span class=\"kw\">class<\/span> Vehicle:\n    <span class=\"kw\">def<\/span> <span class=\"fn\">__init__<\/span>(self, brand):\n        self.brand = brand\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">start_engine<\/span>(self):\n        <span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;{self.brand} engine started.&quot;<\/span>)\n\n<span class=\"kw\">class<\/span> <span class=\"fn\">Car<\/span>(Vehicle):\n    <span class=\"kw\">def<\/span> <span class=\"fn\">__init__<\/span>(self, brand, model):\n        <span class=\"fn\">super<\/span>().<span class=\"fn\">__init__<\/span>(brand) <span class=\"cm\"># Call parent&#039;s constructor<\/span>\n        self.model = model\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">drive<\/span>(self):\n        <span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;The {self.brand} {self.model} is driving on four wheels.&quot;<\/span>)\n\n<span class=\"kw\">class<\/span> <span class=\"fn\">Motorcycle<\/span>(Vehicle):\n    <span class=\"kw\">def<\/span> <span class=\"fn\">__init__<\/span>(self, brand, type_moto):\n        <span class=\"fn\">super<\/span>().<span class=\"fn\">__init__<\/span>(brand)\n        self.type_moto = type_moto\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">ride<\/span>(self):\n        <span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;The {self.brand} {self.type_moto} is riding on two wheels.&quot;<\/span>)\n\n<span class=\"cm\"># Create objects of child classes<\/span>\nmy_car = <span class=\"fn\">Car<\/span>(<span class=\"st\">&quot;Ford&quot;<\/span>, <span class=\"st\">&quot;Focus&quot;<\/span>)\nmy_bike = <span class=\"fn\">Motorcycle<\/span>(<span class=\"st\">&quot;Harley-Davidson&quot;<\/span>, <span class=\"st\">&quot;Cruiser&quot;<\/span>)\n\n<span class=\"cm\"># Child classes use methods from parent<\/span>\nmy_car.<span class=\"fn\">start_engine<\/span>()\nmy_bike.<span class=\"fn\">start_engine<\/span>()\n\n<span class=\"cm\"># Child classes use their own methods<\/span>\nmy_car.<span class=\"fn\">drive<\/span>()\nmy_bike.<span class=\"fn\">ride<\/span>()<\/code><\/pre><\/div>\n\n\n\n<p>This code outputs:<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb961a\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Ford engine started.\nHarley-Davidson engine started.\nThe Ford Focus is driving on four wheels.\nThe Harley-Davidson Cruiser is riding on two wheels.<\/code><\/pre><\/div>\n\n\n\n<p>The <code>Car<\/code> and <code>Motorcycle<\/code> classes inherit <code>start_engine()<\/code> from <code>Vehicle<\/code>. They also have their own specific methods (<code>drive()<\/code> and <code>ride()<\/code>).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"4-encapsulation\">4. Encapsulation<\/h2>\n\n\n\n<p><strong>Encapsulation<\/strong> means bundling data (attributes) and methods that work on that data into a single unit (a class). It also means hiding the internal details of how a class works. You expose only what is necessary to the outside world.<\/p>\n\n\n\n<p>Think of a remote control for a TV. You use buttons to change channels or volume. You do not need to know how the remote's circuits work inside. Encapsulation works like this.<\/p>\n\n\n\n<p>In Python, you can indicate that an attribute or method is \"private\" or \"protected\" by using underscores:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Public:<\/strong> Attributes\/methods without underscores or with a single underscore. You can access them from anywhere.<\/li>\n\n\n\n<li><strong>Protected:<\/strong> Attributes\/methods starting with a single underscore (e.g., <code>_protected_attribute<\/code>). This is a convention, meaning \"don't directly access this from outside the class unless you know what you are doing.\" Python does not strictly prevent access.<\/li>\n\n\n\n<li><strong>Private:<\/strong> Attributes\/methods starting with two underscores (e.g., <code>__private_attribute<\/code>). Python \"mangles\" these names to make them harder to access directly from outside the class.<\/li>\n<\/ul>\n\n\n\n<div id=\"copy-6a3ba0feb967b\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code><span class=\"kw\">class<\/span> BankAccount:\n    <span class=\"kw\">def<\/span> <span class=\"fn\">__init__<\/span>(self, initial_balance):\n        self.__balance = initial_balance <span class=\"cm\"># Private attribute<\/span>\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">deposit<\/span>(self, amount):\n        <span class=\"kw\">if<\/span> amount &gt; :\n            self.__balance += amount\n            <span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;Deposited {amount}. New balance: {self.__balance}&quot;<\/span>)\n        <span class=\"kw\">else<\/span>:\n            <span class=\"fn\">print<\/span>(<span class=\"st\">&quot;Deposit amount must be positive.&quot;<\/span>)\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">withdraw<\/span>(self, amount):\n        <span class=\"kw\">if<\/span> amount &gt;  <span class=\"kw\">and<\/span> self.__balance &gt;= amount:\n            self.__balance -= amount\n            <span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;Withdrew {amount}. New balance: {self.__balance}&quot;<\/span>)\n        <span class=\"kw\">else<\/span>:\n            <span class=\"fn\">print<\/span>(<span class=\"st\">&quot;Invalid withdrawal amount or insufficient funds.&quot;<\/span>)\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">get_balance<\/span>(self):\n        <span class=\"kw\">return<\/span> self.__balance\n\n<span class=\"cm\"># Create a bank account object<\/span>\nmy_account = <span class=\"fn\">BankAccount<\/span>(<span class=\"nm\">1000<\/span>)\n\n<span class=\"cm\"># Interact with the account using public methods<\/span>\nmy_account.<span class=\"fn\">deposit<\/span>(<span class=\"nm\">200<\/span>)\nmy_account.<span class=\"fn\">withdraw<\/span>(<span class=\"nm\">500<\/span>)\n<span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;Current balance: {my_account.get_balance()}&quot;<\/span>)\n\n<span class=\"cm\"># Trying to access a &quot;private&quot; attribute directly (Python name mangles it)<\/span>\n<span class=\"cm\"># print(my_account.__balance) # This will cause an AttributeError<\/span><\/code><\/pre><\/div>\n\n\n\n<p>This code outputs:<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb968a\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Deposited <span class=\"nm\">200<\/span>. New balance: <span class=\"nm\">1200<\/span>\nWithdrew <span class=\"nm\">500<\/span>. New balance: <span class=\"nm\">700<\/span>\nCurrent balance: <span class=\"nm\">700<\/span><\/code><\/pre><\/div>\n\n\n\n<p>You manage the <code>__balance<\/code> (private data) through <code>deposit()<\/code>, <code>withdraw()<\/code>, and <code>get_balance()<\/code> methods. This prevents direct, uncontrolled changes to the balance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5-polymorphism\">5. Polymorphism<\/h2>\n\n\n\n<p><strong>Polymorphism<\/strong> means \"many forms.\" It lets you use the same function name for different types of objects. This means one function or method can act in many forms.<\/p>\n\n\n\n<p>Think of a <code>speak()<\/code> method. A <code>Dog<\/code> object might <code>speak()<\/code> by barking, while a <code>Cat<\/code> object might <code>speak()<\/code> by meowing. The method name is the same, but the behavior is different based on the object type.<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb96c2\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code><span class=\"kw\">class<\/span> Dog:\n    <span class=\"kw\">def<\/span> <span class=\"fn\">speak<\/span>(self):\n        <span class=\"fn\">print<\/span>(<span class=\"st\">&quot;Woof!&quot;<\/span>)\n\n<span class=\"kw\">class<\/span> Cat:\n    <span class=\"kw\">def<\/span> <span class=\"fn\">speak<\/span>(self):\n        <span class=\"fn\">print<\/span>(<span class=\"st\">&quot;Meow!&quot;<\/span>)\n\n<span class=\"kw\">class<\/span> Duck:\n    <span class=\"kw\">def<\/span> <span class=\"fn\">speak<\/span>(self):\n        <span class=\"fn\">print<\/span>(<span class=\"st\">&quot;Quack!&quot;<\/span>)\n\n<span class=\"cm\"># Function that takes an animal object and makes it speak<\/span>\n<span class=\"kw\">def<\/span> <span class=\"fn\">make_animal_speak<\/span>(animal):\n    animal.<span class=\"fn\">speak<\/span>()\n\n<span class=\"cm\"># Create animal objects<\/span>\nmy_dog = <span class=\"fn\">Dog<\/span>()\nmy_cat = <span class=\"fn\">Cat<\/span>()\nmy_duck = <span class=\"fn\">Duck<\/span>()\n\n<span class=\"cm\"># Call the same function with different animal objects<\/span>\n<span class=\"fn\">make_animal_speak<\/span>(my_dog)\n<span class=\"fn\">make_animal_speak<\/span>(my_cat)\n<span class=\"fn\">make_animal_speak<\/span>(my_duck)<\/code><\/pre><\/div>\n\n\n\n<p>This code outputs:<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb96c9\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Woof!\nMeow!\nQuack!<\/code><\/pre><\/div>\n\n\n\n<p>The <code>make_animal_speak()<\/code> function does not care what type of animal it receives. It just calls the <code>speak()<\/code> method, and the correct <code>speak()<\/code> method for that animal runs. This makes your code more flexible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"6-abstraction\">6. Abstraction<\/h2>\n\n\n\n<p><strong>Abstraction<\/strong> means showing only the essential features of an object and hiding complex implementation details. It lets you focus on what an object does, not how it does it.<\/p>\n\n\n\n<p>Imagine driving a car. You use the steering wheel, pedals, and gear stick. You do not need to know the complex mechanics of the engine or transmission. Abstraction hides these details.<\/p>\n\n\n\n<p>In Python, you can achieve abstraction using abstract classes and methods. An abstract class cannot be created directly. It provides a blueprint that other classes must follow. The <code>abc<\/code> module (Abstract Base Classes) helps you do this.<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb9718\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code><span class=\"kw\">from<\/span> abc <span class=\"kw\">import<\/span> ABC, abstractmethod\n\n<span class=\"kw\">class<\/span> <span class=\"fn\">Shape<\/span>(ABC): <span class=\"cm\"># Shape is an abstract base class<\/span>\n    @abstractmethod\n    <span class=\"kw\">def<\/span> <span class=\"fn\">area<\/span>(self):\n        <span class=\"kw\">pass<\/span> <span class=\"cm\"># Abstract method - must be implemented by child classes<\/span>\n\n    @abstractmethod\n    <span class=\"kw\">def<\/span> <span class=\"fn\">perimeter<\/span>(self):\n        <span class=\"kw\">pass<\/span> <span class=\"cm\"># Abstract method<\/span>\n\n<span class=\"kw\">class<\/span> <span class=\"fn\">Circle<\/span>(Shape):\n    <span class=\"kw\">def<\/span> <span class=\"fn\">__init__<\/span>(self, radius):\n        self.radius = radius\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">area<\/span>(self):\n        <span class=\"kw\">return<\/span> <span class=\"nm\">3.14<\/span> * self.radius * self.radius\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">perimeter<\/span>(self):\n        <span class=\"kw\">return<\/span> <span class=\"nm\">2<\/span> * <span class=\"nm\">3.14<\/span> * self.radius\n\n<span class=\"kw\">class<\/span> <span class=\"fn\">Square<\/span>(Shape):\n    <span class=\"kw\">def<\/span> <span class=\"fn\">__init__<\/span>(self, side):\n        self.side = side\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">area<\/span>(self):\n        <span class=\"kw\">return<\/span> self.side * self.side\n\n    <span class=\"kw\">def<\/span> <span class=\"fn\">perimeter<\/span>(self):\n        <span class=\"kw\">return<\/span> <span class=\"nm\">4<\/span> * self.side\n\n<span class=\"cm\"># Create objects<\/span>\nmy_circle = <span class=\"fn\">Circle<\/span>(<span class=\"nm\">5<\/span>)\nmy_square = <span class=\"fn\">Square<\/span>(<span class=\"nm\">4<\/span>)\n\n<span class=\"cm\"># Calculate and print<\/span>\n<span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;Circle area: {my_circle.area()}&quot;<\/span>)\n<span class=\"fn\">print<\/span>(f<span class=\"st\">&quot;Square perimeter: {my_square.perimeter()}&quot;<\/span>)\n\n<span class=\"cm\"># Trying to create an abstract class directly will raise an error<\/span>\n<span class=\"cm\"># abstract_shape = Shape() # This would give a TypeError<\/span><\/code><\/pre><\/div>\n\n\n\n<p>This code outputs:<\/p>\n\n\n\n<div id=\"copy-6a3ba0feb9728\" class=\"copy-code-wrapper\"><div class=\"copy-code-header\"><span class=\"copy-code-lang\">python<\/span><button type=\"button\" class=\"copy-button\" aria-label=\"Copy code\"><svg class=\"icon-copy\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M16 1H4C2.9 1 2 1.9 2 3V17H4V3H16V1Z\"\/><path d=\"M20 5H8C6.9 5 6 5.9 6 7V21C6 22.1 6.9 23 8 23H20C21.1 23 22 22.1 22 21V7C22 5.9 21.1 5 20 5ZM20 21H8V7H20V21Z\"\/><\/svg><svg class=\"icon-check\" viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4z\"\/><\/svg><span class=\"btn-label\">Copy<\/span><\/button><\/div><pre><code>Circle area: <span class=\"nm\">78.5<\/span>\nSquare perimeter: <span class=\"nm\">16<\/span><\/code><\/pre><\/div>\n\n\n\n<p>The <code>Shape<\/code> class defines <code>area()<\/code> and <code>perimeter()<\/code> as abstract methods. Any class inheriting from <code>Shape<\/code> must implement these methods. You focus on the idea of a <code>Shape<\/code> having an area and perimeter, not the exact calculation method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>OOP concepts in Python help you write organized, reusable, and flexible code. Understanding classes and objects lets you model real-world problems in your programs. Inheritance helps you reuse code. Encapsulation protects your data. Polymorphism makes your code adaptable. Abstraction simplifies complex systems.<\/p>\n\n\n\n<p>Understanding OOP concepts is a major milestone in your journey to becoming a developer. However, if any of these topics still feel a bit complex, remember that every expert started with the basics. To ensure you have a rock-solid foundation in Python, we recommend trying our Free Python Course. It is tailored for beginners to help them move from zero coding experience to writing functional scripts, making it the perfect stepping stone to the advanced concepts covered in this guide<\/p>\n\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Free Course<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" class=\"courses-cta-title-link\">Python Fundamentals for Beginners Free Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master Python basics, from variables to data structures and control flow. Solve real-time problems and build practical skills using Jupyter Notebook.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>13.5 hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>4.55<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" class=\"courses-cta-button\">\n                Enroll for Free\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Object-Oriented Programming (OOP) is a way of organizing your code. It lets you create programs that are easy to understand and manage. In Python, OOP uses \"objects\" to represent real-world things or ideas. These objects combine data and the actions that can be performed on that data. Using OOP helps you write code that is [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":31908,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796],"content_type":[],"class_list":["post-47857","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Learn Object-Oriented Programming in Python<\/title>\n<meta name=\"description\" content=\"Learn Object-Oriented Programming (OOP) concepts in Python. Understand how these concepts help in building clean and efficient Python programs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OOPs Concepts in Python\" \/>\n<meta property=\"og:description\" content=\"Learn Object-Oriented Programming (OOP) concepts in Python. Understand how these concepts help in building clean and efficient Python programs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-25T00:39:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-28T09:31:14+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1255\" \/>\n\t<meta property=\"og:image:height\" content=\"836\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"OOPs Concepts in Python\",\"datePublished\":\"2021-10-25T00:39:47+00:00\",\"dateModified\":\"2026-05-28T09:31:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/\"},\"wordCount\":1680,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/iStock-1139255812.jpg\",\"keywords\":[\"python\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/\",\"name\":\"Learn Object-Oriented Programming in Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/iStock-1139255812.jpg\",\"datePublished\":\"2021-10-25T00:39:47+00:00\",\"dateModified\":\"2026-05-28T09:31:14+00:00\",\"description\":\"Learn Object-Oriented Programming (OOP) concepts in Python. Understand how these concepts help in building clean and efficient Python programs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/iStock-1139255812.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/iStock-1139255812.jpg\",\"width\":1255,\"height\":836,\"caption\":\"Python Programming Language on server room background. Programing workflow abstract algorithm concept on virtual screen.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/oops-concepts-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"OOPs Concepts in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Learn Object-Oriented Programming in Python","description":"Learn Object-Oriented Programming (OOP) concepts in Python. Understand how these concepts help in building clean and efficient Python programs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/","og_locale":"en_US","og_type":"article","og_title":"OOPs Concepts in Python","og_description":"Learn Object-Oriented Programming (OOP) concepts in Python. Understand how these concepts help in building clean and efficient Python programs.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-10-25T00:39:47+00:00","article_modified_time":"2026-05-28T09:31:14+00:00","og_image":[{"width":1255,"height":836,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"OOPs Concepts in Python","datePublished":"2021-10-25T00:39:47+00:00","dateModified":"2026-05-28T09:31:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/"},"wordCount":1680,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg","keywords":["python"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/","url":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/","name":"Learn Object-Oriented Programming in Python","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg","datePublished":"2021-10-25T00:39:47+00:00","dateModified":"2026-05-28T09:31:14+00:00","description":"Learn Object-Oriented Programming (OOP) concepts in Python. Understand how these concepts help in building clean and efficient Python programs.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg","width":1255,"height":836,"caption":"Python Programming Language on server room background. Programing workflow abstract algorithm concept on virtual screen."},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"OOPs Concepts in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg",1255,836,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812-1024x682.jpg",1024,682,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg",1255,836,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812.jpg",1255,836,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812-640x836.jpg",640,836,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/04\/iStock-1139255812-150x100.jpg",150,100,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Object-Oriented Programming (OOP) is a way of organizing your code. It lets you create programs that are easy to understand and manage. In Python, OOP uses \"objects\" to represent real-world things or ideas. These objects combine data and the actions that can be performed on that data. Using OOP helps you write code that is&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/47857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=47857"}],"version-history":[{"count":7,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/47857\/revisions"}],"predecessor-version":[{"id":118097,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/47857\/revisions\/118097"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/31908"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=47857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=47857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=47857"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=47857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}