Last modified: Dec 04, 2026

Python Polymorphism Types

Polymorphism sounds like a scary word. In practice, it just means "many forms" — the same method name can behave differently depending on the object calling it. Python leans into this idea hard, and once it clicks, your code gets shorter and easier to extend.

Let's walk through the main types you'll actually run into. No academic fluff, just code you can run today.

What Polymorphism Really Means in Python

At its core, polymorphism lets you write code that works with objects of different types through a shared interface. You call a method, and each object decides how to respond. Python doesn't need a special keyword for this — it's baked into the language.

A quick taste before the details:


class Dog:
    def speak(self):
        return "Woof!"

class Cat:
    def speak(self):
        return "Meow!"

for animal in (Dog(), Cat()):
    print(animal.speak())

Woof!
Meow!

Notice there's no shared base class here. Both objects just have a speak method, and the loop doesn't care what they are. That's the spirit of Python polymorphism in a nutshell.

Type 1: Method Overriding (Subtype Polymorphism)

The classic form. A child class replaces a method from its parent, and calling that method on a child instance runs the child's version. This is where inheritance and polymorphism shake hands.

If you're still shaky on the parent-child relationship, start with this single inheritance in Python example before going further.


class Shape:
    def area(self):
        return 0

class Square(Shape):
    def __init__(self, side):
        self.side = side

    def area(self):
        return self.side ** 2

class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return round(3.14 * self.radius ** 2, 2)

shapes = [Square(4), Circle(3)]
for s in shapes:
    print(s.area())

16
28.26

Each subclass overrides area, so the loop stays dumb and the objects do the thinking. That's the whole trick.

Using super() to Extend, Not Replace

Sometimes you want the parent behavior plus a little extra. That's what super is for. It calls the parent version so you don't repeat yourself.


class Animal:
    def speak(self):
        return "Some sound"

class Dog(Animal):
    def speak(self):
        return super().speak() + " — woof!"

If you want a wider view of how overriding fits into the class hierarchy, the Python class polymorphism guide covers it well.

Type 2: Duck Typing

Python doesn't check types before calling methods. If it walks like a duck and quacks like a duck, it's a duck. This is duck typing, and it's probably the most Pythonic form of polymorphism.

No inheritance required. No interface declarations. Just the right method names.


class FileLogger:
    def log(self, msg):
        print(f"[FILE] {msg}")

class ConsoleLogger:
    def log(self, msg):
        print(f"[CONSOLE] {msg}")

def write_log(logger, message):
    logger.log(message)  # any object with .log() works

write_log(FileLogger(), "Started")
write_log(ConsoleLogger(), "Started")

[FILE] Started
[CONSOLE] Started

Here's the thing — duck typing is flexible, but it fails at runtime, not at definition time. If you pass an object without log, you get an AttributeError. So write tests, and use type hints if your team likes them.

Type 3: Operator Overloading

Python lets you define how operators like + and == behave for your own classes. That's polymorphism at the operator level, and it's done through dunder methods.


class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __repr__(self):
        return f"Vector({self.x}, {self.y})"

print(Vector(1, 2) + Vector(3, 4))

Vector(4, 6)

The __add__ method is what makes + work. There are dozens more where that came from — see this Python dunder methods list for the full picture.

Type 4: Method Overloading (Sort Of)

Python doesn't support method overloading the way Java does. You can't define two methods with the same name and different signatures. The second one wins, silently.

But you can fake it. Default arguments and *args handle most cases, and functools.singledispatch handles the rest when you really need type-based dispatch.


from functools import singledispatch

@singledispatch
def describe(x):
    return "Unknown"

@describe.register
def _(x: int):
    return "Integer"

@describe.register
def _(x: str):
    return "String"

print(describe(5))
print(describe("hi"))

Integer
String

Honestly, most of the time you won't need this. A simple isinstance check or a default argument is enough. Reach for singledispatch only when the logic gets genuinely messy.

Type 5: Polymorphism Through Inheritance

Inheritance-based polymorphism is the most structured option. You define a base class, subclasses override its methods, and code that expects the base class works with any subclass.

This is where abstract base classes come in handy. They force subclasses to implement certain methods, which catches mistakes early.


from abc import ABC, abstractmethod

class Payment(ABC):
    @abstractmethod
    def pay(self, amount):
        pass

class CardPayment(Payment):
    def pay(self, amount):
        print(f"Paid {amount} with card")

class CashPayment(Payment):
    def pay(self, amount):
        print(f"Paid {amount} in cash")

for p in (CardPayment(), CashPayment()):
    p.pay(50)

Paid 50 with card
Paid 50 in cash

If you want to compare this against other inheritance styles, the article on types of Python inheritance lays them all out side by side.

Polymorphism vs. Inheritance: Not the Same Thing

People mix these up constantly. Inheritance is about code reuse and hierarchy. Polymorphism is about behavior — the same call doing different things. You can have polymorphism without inheritance (duck typing proves it), and inheritance without polymorphism (a subclass that changes nothing).

Keep them separate in your head and you'll design cleaner classes.

When to Use Which Type

There's no single right answer, but a few rules of thumb help:

  • Use duck typing for small, flexible code where a shared interface is obvious.
  • Use inheritance + overriding when subclasses genuinely share behavior and state.
  • Use abstract base classes when you want to enforce a contract across a family of classes.
  • Use operator overloading sparingly — only when it makes the class feel natural, like numbers or collections.

My opinion: most beginners overuse inheritance. Duck typing is simpler and does the job in 80% of cases. Reach for a base class when you actually need shared code, not just shared method names.

A Quick Common Mistake

New developers often assume Python checks types before calling methods. It doesn't. So a typo in a method name only blows up when that line runs, sometimes deep in a program.

Two habits help. First, keep method names consistent across related classes. Second, run your code paths in tests so the failure shows up early.

Conclusion

Python polymorphism comes in several flavors: overriding, duck typing, operator overloading, single dispatch, and inheritance-based contracts. They all share the same goal — one call, many behaviors. Pick the simplest one that solves your problem, and don't over-engineer. That's it.