How to pass default parameter value in Python function

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.

Answers 1
  • Pass default parameter value to Python function

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

    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