capypad
0 day streak
python / beginner
Snippet

Functions with Default Parameters

You can provide a default value for a function parameter. If the caller doesn't provide an argument, the default is used.

snippet.py
python
1
2
3
4
5
def greet(name="Guest"):
print("Hello, " + name)
 
greet() # Uses default
greet("Alice") # Uses provided value
Breakdown
1
name="Guest"
Defines 'Guest' as the fallback value if no name is provided.
2
greet()
Calls the function without arguments, triggering the default behavior.