Home Tutorials Python OOP Concepts Polymorphism
Polymorphism

Polymorphism


19. Polymorphism

Polymorphism allows the same method name or interface to behave differently for different objects. In Python, this is commonly shown through method overriding and duck typing.

Syntax

class A:
    def show(self):
        pass

class B(A):
    def show(self):
        print("Different behavior")

Example

class Cat:
    def sound(self):
        print("Meow")

class Dog:
    def sound(self):
        print("Bark")

for animal in [Cat(), Dog()]:
    animal.sound()

Output

Meow
Bark
Example

🏋️ Test Yourself With Exercises

Take our quiz on Polymorphism to test your knowledge.

Browse Quizzes »