In Python you can specify a default value for a function argument. It's nice for when a function has arguments that are "optional". You as the function definer can specify a specific default value in case the caller doesn't provide one.
A default value is created by using the assignment (=
) operator in the function signature.
def get_greeting(email, name="there"):
print("Hello", name, "welcome! You've registered your email:", email)
get_greeting("lane@example.com", "Lane")
# Hello Lane welcome! You've registered your email: lane@example.com
get_greeting("lane@example.com")
# Hello there welcome! You've registered your email: lane@example.com
If the second parameter is omitted, the default "there"
value will be used in its place. As you may have guessed, for this structure to work, optional arguments (the ones with defaults) must come after all required arguments.
Complete the get_punched
and get_slashed
functions. They both take 2 integers as arguments, health
and armor
.
Focus Editor
Alt+Shift+]
Login to Submit
Login to Run
Login to view solution