/  Technology   /  Function Overloading in Python

Function Overloading in Python

Function Overloading: 

If a class has multiple functions with same names but different parameters, then they are said to be overloaded. 

 

Function overloading allows you to use the same name for different functions, to do the same or different tasks in the same class. If you need to perform only one operation but with a different number or argument types, you can simply overload the function. 

 

For example,

#include<iostream>
using namespace std;
int sum(int x,int y)
{ 
cout<< x+y; 
}
double sum(double x,double y)
{ 
cout << x+y; 
}
int main()
{ 
sum (10,20);
sum(10.5,20.5);
return 0;
}

 

Output:

 

Leave a comment