---
title: "Python Polymorphism: 3 Neat Examples"
description: "Python supports polymorphism. Out of that, three are popular. Here are examples you can easily explain in interviews."
url: https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/
date: 2022-09-04
modified: 2026-10-05
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2022/09/pexels-photo-4505166.jpeg?fit=1880%2C1253&ssl=1
categories: ["Python"]
tags: ["Polymorphism examples"]
type: post
lang: en
---

# Python Polymorphism: 3 Neat Examples

![Python Polymorphism: 3 Neat Examples](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/12/python_polymorphism_examples_1_800x400-1.jpg?resize=800%2C400&ssl=1)***Created at Canava***

Poly means many, and morphism means forms. So polymorphism means many forms. Python supports [**object-oriented concepts**](https://www.biganalytics.me/2020/02/python-oops-concepts.html) like java. Below, you will find examples that explain the polymorphism of method/object/variable. 

**ON THIS PAGE**

1. [Polymorphism python](https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/#polymorphism-python)
   1. [Method polymorphism](https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/#method-polymorphism)
   2. [Object polymorphism](https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/#object-polymorphism)
   3. [Variable polymorphism](https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/#variable-polymorphism)

## **Polymorphism python**

A rectangle appears in different shapes in different situations. Similarly [polymorphism](https://srinimf.com/2022/01/30/how-to-say-about-python-oops-concepts/) works. Here are three types of polymorphism in python VIZ: Method, Object, and Variable.

![Polymorphism in Python real time examples](https://i0.wp.com/srinimf.com/wp-content/uploads/2022/09/aa.png?resize=800%2C400&ssl=1)

### **Method polymorphism**

Here is the method with three[arguments](https://srinimf.com/2018/12/31/python-pass-by-value-vs-reference-read-today/). The third argument value initialized with zero (c=0). I have supplied one time two arguments. The other time three arguments. For each, it gives an output. This way is called **method polymorphism**.

```
def meth1(a, b, c=0):
    return a + b + c

#Method polymorphism
print(meth1(1, 2))
print(meth1(1, 2, 3))
```

Method polymorphism

Output

```
3
6

** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

### **Object polymorphism**

Here the same object gives two different results. Let us see how it works. Here, the [class](https://srinimf.com/2021/12/18/here-is-python-program-displays-student-details/) puppy assigns to two different objects with different inputs. The result is different – not the same. So it tells how **object polymorphism** works.

```
class puppy:
    
    def obj1(self, value):
        print(" My Value is : ", value)

#Object polymorphism
c1=puppy()
c2=puppy()

c1.obj1(400)
c2.obj1(300)
```

Output

```
My Value is :  400
 My Value is :  300

** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

### **Variable polymorphism**

Here a class can take multiple variables(n). There is no fixed limit. And you will get a result different for each input.

```
class Demo:
    def mymul(self,*vars):
        mytotal=1
        for loop in vars:
            mytotal *= loop
            print("The Product of arguments is :",mytotal)

myobj=Demo()

myobj.mymul(10,20,30)
myobj.mymul(10,20)
myobj.mymul(10)
myobj.mymul()
myobj.mymul(10,20,30,40)
```

Output

For each input, you will get an output. The concept of this kind of polymorphism is called python **variable polymorphism**.

```
The Product of arguments is : 10
The Product of arguments is : 200
The Product of arguments is : 6000
The Product of arguments is : 10
The Product of arguments is : 200
The Product of arguments is : 10
The Product of arguments is : 10
The Product of arguments is : 200
The Product of arguments is : 6000
The Product of arguments is : 240000

** Process exited - Return Code: 0 **
Press Enter to exit terminal
```

Related

- [Exploring Python’s OOP Principles with Examples](https://srinimf.com/2022/01/30/how-to-say-about-python-oops-concepts/)DateJanuary 30, 2022
- [How to Understand Python Oops Concepts [ Simplified]](https://srinimf.com/2021/08/16/python-inheritance-polymorphism-overloading-tricky-examples/)DateAugust 16, 2021
- [Here is Why You Need to Learn Java for Hadoop Jobs](https://srinimf.com/2016/02/03/how-much-java-skills-you-need-for-hadoop-career/)DateFebruary 3, 2016

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2022%2F09%2F04%2F3-python-polymorphism-real-time-examples-helpful-for-interviews%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2022%2F09%2Fpexels-photo-4505166.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=Python%20Polymorphism%3A%203%20Neat%20Examples)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2022/09/04/3-python-polymorphism-real-time-examples-helpful-for-interviews/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20Python%20Polymorphism%3A%203%20Neat%20Examples&body=https%3A%2F%2Fsrinimf.com%2F2022%2F09%2F04%2F3-python-polymorphism-real-time-examples-helpful-for-interviews%2F&share=email)
-

### Like this:

Like Loading…