Functions in Python

Functions in Python are defined using the def keyword.
This is a simple Python function that adds 2 numbers and prints the result.

def add(x,y):
    return x+y

a=add(2,3)
print(a)


Output

python output console

There is no function overloading in Python, however by the use of default value parameters we can implement overloading.
Three overloaded functions:

def add(x=0,y=0):
    return x+y

print(add())
print(add(1))
print(add(1,2))


Output

python output console

 

Leave a Reply