How to pass default parameter value in Python function

Updated at 06-Jan-2022, By samar

How to pass default parameter value in Python function

With this article, we’ll look at some examples of how to address the "How to pass default parameter value in Python function" problem.

You can pass default parameter value to python function while defining the function with passing value to parameter after = operator. Here we have code snippet which will help to pass the default value to function in python.
  • Pass default parameter value to Python function

    def my_function(country = "INDIA"):
      print("I am from " + country)
    
    my_function()
    my_function("USA")
    

    Output:

    I am from INDIA
    I am from USA

    We can pass default parameter value to function while defining the function in Python. Here we have pass INDIA as default value to function. It will return INDIA as output if we did not pass value to function while calling the function.

Back to code snippet queries related python