

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 6
click for more info
Not enough gems
Cost: 6 gems
1: Functions
incomplete
2: Function Review
incomplete
3: Multiple Parameters
incomplete
4: Printing vs. Returning
incomplete
5: Where to Declare Functions
incomplete
6: Order of Functions
incomplete
7: Community
incomplete
8: Boots Interview
incomplete
9: Solutions
incomplete
10: None Return
incomplete
11: Multiple Return Values
incomplete
12: Parameters vs. Arguments
incomplete
13: Default Values
incomplete
14: Curse
incomplete
15: The Training Grounds
incomplete
16: Enchant and Attack
incomplete
17: Archmage
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
In Python you can specify a default value for a function parameter. It's useful when a function has parameters that are "optional." You can specify a 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("[email protected]", "Lane")
# Hello Lane, welcome! You've registered your email: [email protected]
get_greeting("[email protected]")
# Hello there, welcome! You've registered your email: [email protected]
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 parameters (the ones with defaults) must come after all required parameters.
Complete the get_punched and get_slashed functions. They both take 2 integers as arguments, health and armor.