Defining a Function with default parameters

A python function can be used a default parameter value. In case, if you call the function without argument, it uses the default parameter value. This is very useful if you do not know the value to pass it.

Example:

def get_location(city = ”London”):
    print(“my work location is:”+city)

get_location("Bangalore")
get_location("")

In the above example, when you call the get_location function with the argument “Bangalore”, it uses that value and print city as “Bangalore”. When you call the get_location function without the argument value, it uses the default parameter value and print city as “London”.

Calling a Function with number of arguments

A Python function can be defined with multiple parameters and called with same number of arguments. When you defined the function with 3 parameters, you should call the function with 3 arguments only so that the arguments values passed to respective function parameters in parentheses.

Example:

In the below example, multiply() is a python function with 3 parameters i.e. num1, num2 & num3

def multiply(num1, num2, num3):
    print(“Multiplication result:”+ num1 * num2 * num3)

multiply(2, 5, 10)      # calling a function with arguments 2, 5 and 10.
multiply(25, 1.5, 2)    # calling a function with arguments 25, 1.5 and 2.


Related Tutorials