How to pass default parameter value in Python function

Created at 07-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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.