Polymorphism in Python programming is an important concept of OOP. When we have many classes that are related to each other by inheritance and more than one form of a class.
class Animal: #'Animal' is name of class.
def __init__(self, name=''): #this is parameterized constructor.
self.name = name
def talk(self):
pass
class Cat(Animal): #class 'Cat' is Child of class 'Animal'.
def talk(self):
print("Meow!")
class Dog(Animal): #class 'Dog' is Child of class 'Animal'.
def talk(self):
print("Woof!")
a = Animal() #'a' is object of class 'Animal'.
a.talk()
c = Cat("Missy") #'c' is object of class 'Cat'.
c.talk()
d = Dog("Rocky") #'d' is object of class 'Dog'.
d.talk()