Function overloading in Python - Area of a shape

# Functions - Area of a shape

# Function overloading 


"""

install multipledispatch as below from command prompt


pip install multipledispatch


"""


from multipledispatch import dispatch


@dispatch(int)

def fnShape(x):

print("Area of square = ",(x*x))

@dispatch(float)

def fnShape(x):

print("Area of circle = ",(3.142*x*x))


@dispatch(int,int)

def fnShape(x,y):

print("Area of rectangle = ",(x*y))


# The three function calls differ by number and datatype


fnShape(5) # int

fnShape(2.1)         # float

fnShape(5,6)         # int,int



No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu