python / beginner
Snippet
Default Argument Values
You can assign a default value to a function parameter. If the caller doesn't provide a value, the default is used.
snippet.py
1
2
3
4
5
def greet(name="Guest"):print("Hello", name)greet()greet("Alice")
Breakdown
1
name="Guest"
Defines 'Guest' as the fallback value for the 'name' parameter.
2
greet()
Calls the function without an argument, so it uses the default value.