Python program to overload multiply-Operator Overloading
#python #program #Python program function Overloading
Programming languages have a feature called function overloading that enables the definition of numerous functions with the same name in a class or namespace but with different argument lists.Operator in programming enables you to create unique behaviours for function.To use of multiplication operator * you can define a special method product in your class in many programming languages.
# product is function and we are trying to overload the product method:-
def
product(a, b):
p
=
a
*
b
print
(p)
# Second product method
def
product(a, b, c):
p
=
a
*
b
*
c
print
(p)
# This line will call the second method product
product(
4
,
5
,
5
)
# This line will call the first method product
product(
4
,
5
)
ERROR!
Conclusion
Python does not support traditional or classic function overloading based on the number or types of arguments like some statically typed languages (e.g., C++ or Java).
This can be done by declaring one or more parameters in the function declaration as None.