Image

Programs - Python - Method Overloading

Program:

# First product method.
# Takes two argument and print their product
def product(a, b):
p = a * b
print(p)


# Second product method.
# Takes three argument and print their product
def product(a, b, c):
p = a * b * c
print(p)

# Uncommenting the below line shows an error, this is because the second function overload the first
# product(4, 5)


# This line will call the second product method
product(4, 5, 5)

Output:

100