Method overloading in python | What is method Overloading |


Method overloading in python | What is method Overloading |



What is method Overloading –

In python we can create a method that can be called in different ways . 
So we can have a method that has zero ,one or more numbers of parameters and depending on the method definition we can called it with zero,one or more arguments . this is method overloading in python .


Method overloading in python | What is method Overloading |
Method Overloading 





Method Overloading –

Method Overloading Means Several ways to call a method.
In python you can define a method in such a way that there are multiple way to call it .
Method Overloading in python is a single method or function ,we can specify  the number of parameters our self .depending on the function definition it can be called with zero ,one ,two or more parameters this is known as method overloading .


Method Overloading


Program -

find area of rectangle and area of square using method overloading

class area:
def ar(self,x=None,y=None):
if (x!=None and y!=None):
return x*y
elif(x!=None):
return x*x
else:
    return 0
ob=area()
print("Area of Square: ",ob.ar(4))
print("Area of Rectangle: ",ob.ar(2,2))





Output -


Area of Square:  16
Area of Rectangle:  4













Post a Comment

Post a Comment (0)

Previous Post Next Post