Python Class Polymorphism
Polymorphism is the process of using an operator or function in different ways for different data input. In practical terms, polymorphism means that if class B
inherits from class A
, it doesn't have to inherit everything about class A; it can do some of the things that class A does differently.
Python uses polymorphism extensively in built-in types. Here we use the same indexing operator for three different data types.
Polymorphism is mostly used when dealing with inheritance.
Here we have two species: a dog and a cat. Both are animals. The Dog
class and the Cat
class inherit the Animal
class. They have a talk method, which gives different output for them.
Last updated