Tutorial 8: OOPs in Python — Overloading and Overriding
Missed previous tutorial ? : Click hare
In this tutorial we will learn about method overloading, method overriding and operator overloading.
Operator Overloading :
- Overloading is achieved using Method and Operator having different functionalities with same name.
- Operator overloading is achieved by allowing same operator to have different meanings.
- These operators work for built-in classes. But the same operator behaves differently with different types.
Let’s see how ‘+’ operator works for built-in classes integer, string and list :

Let’s overload the ‘+’ operator for user-defined classes using special method __add__() :


Method Overloading :
- Method Overloading can be thought as many methods with same name accepting different number of arguments within SAME class.
- This should not be confused with Polymorphism which requires DIFFERENT classes to have same method name and different functionalities.
- Python by default does not support Method Overloading since two methods cannot have the same name in Python.


This error can be done away with if we set the default value to the third argument as shown below :

Method Overriding :
We have already seen method overriding without explicitly mentioning it in inheritance.
One of the three purposes of of inheritance was to overwrite the method of parent class in a derived class, this is known as method overriding.
Refer Tutorial 3 for more information regarding this .
Let’s see it using example given below :

Congratulations !!
You have completed eighth tutorial. Take a deep breathe and move to the next tutorial.