def greet(name="friend"):
print(f"Hello, {name}")Line-by-line explanation
- The function has one parameter.
="friend"gives it a default.- The body displays the selected name.
greet()Line-by-line explanation
- The call provides no name.
- Python uses friend.
- The output is
Hello, friend.
greet("Maya")Line-by-line explanation
- The call provides Maya.
- Maya replaces the default for this call.
- The output is
Hello, Maya.
Tiny Practice
Give the language parameter a default of Python.
Starter template
def show_language(language=CHANGE_ME):
print(language)
show_language()Line-by-line explanation
- The function has one parameter.
- The call provides no argument.
Hint
- Use a string.
- Put Python in quotes.
- Keep the equals sign.
Show Solution
def show_language(language="Python"):
print(language)
show_language()Line-by-line explanation
- The parameter defaults to Python.
- The empty call uses that default.
- Python is displayed.