{"id":36699,"date":"2021-06-15T18:51:00","date_gmt":"2021-06-15T13:21:00","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/"},"modified":"2025-06-12T03:30:09","modified_gmt":"2025-06-11T22:00:09","slug":"polymorphism-in-python","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/","title":{"rendered":"Polymorphism in Python"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"what-is-polymorphism\">What is Polymorphism?<\/h2>\n\n\n\n<p>Polymorphism is a key idea in Object-Oriented Programming (OOP). The word \"polymorphism\" comes from Greek. \"Poly\" means \"many.\" \"Morph\" means \"forms.\" So, polymorphism means \"many forms.\"<\/p>\n\n\n\n<p>In Python, polymorphism allows one thing to do different actions. This could be a function, a method, or an operator. The action it takes depends on the type of data it works with. This means you can call the same method on different objects. Each object will then respond in its own special way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-ways-to-use-polymorphism-in-python\">3 Ways to Use Polymorphism in Python<\/h2>\n\n\n\n<p>You can use polymorphism in Python in a few ways:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>With Built-in Functions: Python's own functions often use polymorphism.<\/li>\n\n\n\n<li>With Class Methods: Different classes can have methods that share the same name.<\/li>\n\n\n\n<li>With Inheritance (Method Overriding): Child classes can change methods they get from their parent classes.<\/li>\n<\/ul>\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<p>Let\u2019s look at each way.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-polymorphism-with-built-in-functions\">1. Polymorphism with Built-in Functions<\/h3>\n\n\n\n<p>Many built-in Python functions work in different ways. Their action changes based on the type of data you give them. The <code>len()<\/code> function is a good example.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When you use <code>len()<\/code> on a string, it counts the characters.<\/li>\n\n\n\n<li>When you use <code>len()<\/code> on a list, it counts the items.<\/li>\n\n\n\n<li>When you use <code>len()<\/code> on a dictionary, it counts the keys.<\/li>\n<\/ul>\n\n\n\n<p>Here\u2019s how <code>len()<\/code> works:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Use len() with a string\nmy_string = &quot;hello&quot;\nprint(len(my_string))\n\n# Use len() with a list\nmy_list = &#x5B;1, 2, 3, 4]\nprint(len(my_list))\n\n# Use len() with a dictionary\nmy_dict = {&quot;a&quot;: 1, &quot;b&quot;: 2}\nprint(len(my_dict))\n<\/pre><\/div>\n\n\n<p>This code outputs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">5<br>4<br>2<\/pre>\n\n\n\n<p>The <code>len()<\/code> function acts differently for each data type. This shows polymorphism. You use one function name. But it behaves in \"many forms\" based on what you give it. This makes <code>len()<\/code> very flexible. You do not need different functions to count items in strings, lists, or dictionaries.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-polymorphism-with-class-methods\">2. Polymorphism with Class Methods<\/h3>\n\n\n\n<p>You can define methods with the same name in different classes. These classes do not need to be related through inheritance. You can still call the same method on objects created from these different classes.<\/p>\n\n\n\n<p>Think about these two classes: <code>Dog<\/code> and <code>Cat<\/code>. Both have a <code>sound()<\/code> method.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Dog:\n    def sound(self):\n        print(&quot;Woof!&quot;)\n\nclass Cat:\n    def sound(self):\n        print(&quot;Meow!&quot;)\n\n# Make objects (instances) from these classes\nmy_dog = Dog()\nmy_cat = Cat()\n\n# Call the same method on different objects\nmy_dog.sound()\nmy_cat.sound()\n<\/pre><\/div>\n\n\n<p>This code outputs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Woof!<br>Meow!<\/pre>\n\n\n\n<p>You call <code>sound()<\/code> on both <code>my_dog<\/code> and <code>my_cat<\/code>. Each object runs its own version of <code>sound()<\/code>. This is polymorphism in action. Each object knows how to make its own sound when <code>sound()<\/code> is called.<\/p>\n\n\n\n<p>You can also put these objects into a list. Then, you can loop through the list. Call the same method on each object:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Dog:\n    def sound(self):\n        print(&quot;Woof!&quot;)\n\nclass Cat:\n    def sound(self):\n        print(&quot;Meow!&quot;)\n\n# Make a list of different animal objects\nanimals = &#x5B;Dog(), Cat()]\n\n# Loop through the list\n# Call the &#039;sound&#039; method on each animal\nfor animal in animals:\n    animal.sound()\n<\/pre><\/div>\n\n\n<p>This code outputs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Woof!<br>Meow!<\/pre>\n\n\n\n<p>The <code>animal.sound()<\/code> call works for both <code>Dog<\/code> and <code>Cat<\/code> objects. This is true even if they are different types. The code stays clean. You do not need separate <code>if\/else<\/code> checks for each animal type. This makes your code simpler. It also makes it easier to expand. If you add a new <code>Cow<\/code> class with a <code>sound()<\/code> method, this loop would still work without any changes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-polymorphism-with-inheritance-method-overriding\">3. Polymorphism with Inheritance (Method Overriding)<\/h3>\n\n\n\n<p>Polymorphism often goes with inheritance. Inheritance is when a child class gets features from a parent class. When a child class gets a method from a parent, it can redefine that method. This is called <b>method overriding<\/b>.<\/p>\n\n\n\n<p>The child class creates its own specific way of doing the inherited method. It essentially replaces the parent's method with its own version.<\/p>\n\n\n\n<p>Here is an example. We have a <code>Vehicle<\/code> parent class. Then we have <code>Car<\/code> and <code>Motorcycle<\/code> child classes:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Vehicle:\n    def describe(self):\n        print(&quot;This is a generic vehicle.&quot;)\n\nclass Car(Vehicle): # Car gets features from Vehicle\n    def describe(self): # Car redefines the describe method\n        print(&quot;This is a sporty car.&quot;)\n\nclass Motorcycle(Vehicle): # Motorcycle gets features from Vehicle\n    def describe(self): # Motorcycle redefines the describe method\n        print(&quot;This is a fast motorcycle.&quot;)\n\n# Make objects from each class\nvehicle = Vehicle()\ncar = Car()\nmotorcycle = Motorcycle()\n\n# Call the describe method on different objects\nvehicle.describe()\ncar.describe()\nmotorcycle.describe()\n<\/pre><\/div>\n\n\n<p>This code outputs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">This is a generic vehicle.<br>This is a sporty car.<br>This is a fast motorcycle.<\/pre>\n\n\n\n<p>Each object\u2019s <code>describe()<\/code> method acts differently. The <code>Car<\/code> and <code>Motorcycle<\/code> classes override the <code>describe()<\/code> method from <code>Vehicle<\/code>. When you call <code>describe()<\/code> on a <code>Car<\/code> object, you get the car\u2019s description. The same happens for the <code>Motorcycle<\/code>. Python knows which <code>describe()<\/code> method to call. It picks the right one based on the object's actual type.<\/p>\n\n\n\n<p>You can also use one function that takes a <code>Vehicle<\/code> object. This function will then work with any of its child classes. It does not need special code for each one:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Vehicle:\n    def describe(self):\n        print(&quot;This is a generic vehicle.&quot;)\n\nclass Car(Vehicle):\n    def describe(self):\n        print(&quot;This is a sporty car.&quot;)\n\nclass Motorcycle(Vehicle):\n    def describe(self):\n        print(&quot;This is a fast motorcycle.&quot;)\n\n# A function that takes any object with a &#039;describe&#039; method\ndef show_description(item):\n    item.describe()\n\n# Make objects\ncar = Car()\nmotorcycle = Motorcycle()\ngeneric_vehicle = Vehicle()\n\n# Call the function with different objects\nshow_description(car)\nshow_description(motorcycle)\nshow_description(generic_vehicle)\n<\/pre><\/div>\n\n\n<p>This code outputs:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">This is a sporty car.<br>This is a fast motorcycle.<br>This is a generic vehicle.<\/pre>\n\n\n\n<p>The <code>show_description()<\/code> function works with <code>Car<\/code>, <code>Motorcycle<\/code>, and <code>Vehicle<\/code> objects. It does not need to know the specific type of vehicle. It just calls the <code>describe()<\/code> method. Python then figures out the correct version to use.<\/p>\n\n\n\n<p>This makes your code more flexible. It also helps you reuse code. If you add a new type of <code>Vehicle<\/code>, like a <code>Truck<\/code>, you only need to give it a <code>describe()<\/code> method. The <code>show_description()<\/code> function will then work with it automatically.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"benefits-of-polymorphism\">Benefits of Polymorphism<\/h2>\n\n\n\n<p>Polymorphism offers several good points in your Python code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b>Flexible Code:<\/b> It helps you write code that can work with different types of objects. You use one simple way to interact with many different objects.<\/li>\n\n\n\n<li><b>Reusable Code:<\/b> You can write one function or method. This one piece of code can then process many different objects. This means less repeated code in your program. You write less code, and it does more work.<\/li>\n\n\n\n<li><b>Easier to Maintain:<\/b> When you add new types of objects, you usually do not need to change existing code. This is true as long as the new types have the necessary methods. This makes updating and fixing your programs simpler.<\/li>\n\n\n\n<li><b>Clearer Code:<\/b> It makes your code cleaner and easier to understand. You avoid writing many complex <code>if\/else<\/code> statements to handle different object types.<\/li>\n<\/ul>\n\n\n\n<p>Mastering polymorphism is a major milestone in your journey to writing professional-grade code that is easy to maintain. However, if any of the concepts in this guide 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 exploring the modules in our Free Python Course. It is tailored for beginners to help them learn at their own pace, making it the perfect stepping stone to the advanced features 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","protected":false},"excerpt":{"rendered":"<p>Polymorphism in Python lets you use the same function name for different types of objects. This means one function or method can act in many forms. It makes your code flexible and easy to manage.<\/p>\n<p>It helps you write code that can work with various objects. You do not need to know their exact type. This saves time. It also makes your programs more adaptable.<\/p>\n","protected":false},"author":41,"featured_media":36893,"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-36699","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 Polymorphism in Python with Examples<\/title>\n<meta name=\"description\" content=\"Polymorphism in Python is widely applied in object-oriented Python programming for a common function name that can be used for different types.\" \/>\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\/polymorphism-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Polymorphism in Python\" \/>\n<meta property=\"og:description\" content=\"Polymorphism in Python is widely applied in object-oriented Python programming for a common function name that can be used for different types.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-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-06-15T13:21:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-11T22:00:09+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1254\" \/>\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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Polymorphism in Python\",\"datePublished\":\"2021-06-15T13:21:00+00:00\",\"dateModified\":\"2025-06-11T22:00:09+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/\"},\"wordCount\":889,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/iStock-1197566248-1.jpg\",\"keywords\":[\"python\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/\",\"name\":\"Learn Polymorphism in Python with Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/iStock-1197566248-1.jpg\",\"datePublished\":\"2021-06-15T13:21:00+00:00\",\"dateModified\":\"2025-06-11T22:00:09+00:00\",\"description\":\"Polymorphism in Python is widely applied in object-oriented Python programming for a common function name that can be used for different types.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/iStock-1197566248-1.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/06\\\/iStock-1197566248-1.jpg\",\"width\":1254,\"height\":836,\"caption\":\"python write on book with laptop keyboard background\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/polymorphism-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\":\"Polymorphism 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 Polymorphism in Python with Examples","description":"Polymorphism in Python is widely applied in object-oriented Python programming for a common function name that can be used for different types.","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\/polymorphism-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Polymorphism in Python","og_description":"Polymorphism in Python is widely applied in object-oriented Python programming for a common function name that can be used for different types.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-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-06-15T13:21:00+00:00","article_modified_time":"2025-06-11T22:00:09+00:00","og_image":[{"width":1254,"height":836,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1.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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Polymorphism in Python","datePublished":"2021-06-15T13:21:00+00:00","dateModified":"2025-06-11T22:00:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/"},"wordCount":889,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1.jpg","keywords":["python"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/","url":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/","name":"Learn Polymorphism in Python with Examples","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1.jpg","datePublished":"2021-06-15T13:21:00+00:00","dateModified":"2025-06-11T22:00:09+00:00","description":"Polymorphism in Python is widely applied in object-oriented Python programming for a common function name that can be used for different types.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-python\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1.jpg","width":1254,"height":836,"caption":"python write on book with laptop keyboard background"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-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":"Polymorphism 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\/06\/iStock-1197566248-1.jpg",1254,836,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1-1024x683.jpg",1024,683,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1.jpg",1254,836,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1.jpg",1254,836,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1-640x836.jpg",640,836,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/06\/iStock-1197566248-1-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":"Polymorphism in Python lets you use the same function name for different types of objects. This means one function or method can act in many forms. It makes your code flexible and easy to manage. It helps you write code that can work with various objects. You do not need to know their exact type.&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/36699","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=36699"}],"version-history":[{"count":15,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/36699\/revisions"}],"predecessor-version":[{"id":108826,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/36699\/revisions\/108826"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/36893"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=36699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=36699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=36699"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=36699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}