Default Arguments in Python
Level 3113 keystrokes
This function has a default argument. If greeting is not provided, it defaults to 'Hello'.
Python code
# Define a function with a default argument# greeting="Hello" means Hello is used if not specified1def greet(name, greeting="Hello"): # Return formatted greeting string2 return f"{greeting}, {name}!"3 # Call with only name - uses default greeting4print(greet("Alice"))# Call with both arguments - overrides default5print(greet("Bob", "Hi"))Output
Hello, Alice! Hi, Bob!
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
"× 10(× 5)× 5,× 3{× 2}× 2:× 1!× 1=× 1