In Python, you can define **default values** for one or more formal arguments in functions. If a function is called without passing a value for an argument, the default value is used. If a value is passed, it **overrides** the default.
# Function definition with default argument
def showinfo(name, city="Hyderabad"):
"This function prints the provided information"
print("Name:", name)
print("City:", city)
# Function calls
showinfo(name="Ansh", city="Delhi") # City is provided, overrides default
showinfo(name="Shrey") # City is not provided, uses default "Hyderabad"
Name: Ansh
City: Delhi
Name: Shrey
City: Hyderabad
# Function definition with default argument
def greet_user(name, greeting="Hello"):
"This function greets the user with a specified greeting"
print(greeting, name)
# Function calls
greet_user(name="Alice", greeting="Good Morning") # Greeting is provided
greet_user(name="Bob") # Greeting is not provided, uses default "Hello"
Good Morning Alice
Hello Bob
