Google News
logo
Python Program to Default Parameter Value
In the following example of Python program that demonstrates how to use default parameter value :
Program :
def greet(name="John"):
    print("Hello, " + name)

greet("Alice")
greet()
Output :
Hello, Alice
Hello, John
In this program, we define a function `greet()` that takes a single parameter `name`. If the caller passes a value for `name`, the function uses it to greet the user. If `name` is not provided, the function uses a default value of "John".

In the example, we call `greet()` twice. The first time, we pass the name "Alice" as a parameter, and the function greets Alice.

The second time, we don't pass any parameter, so the function uses the default value and greets John.