

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 2
click for more info
Not enough gems
Cost: 6 gems
1: Type Hints
incomplete
2: Basic Types
incomplete
3: Function Parameters
incomplete
4: Return Types
incomplete
5: Fixing Type Hints
incomplete
6: List and Set Hints
incomplete
7: Dictionary Hints
incomplete
8: Tuple Hints
incomplete
9: Specific Container Types
incomplete
10: Nested Types
incomplete
11: Optional Values
incomplete
12: Fix Code With Type Hints
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Function parameters can have type hints too! The syntax is the same as variable type hints: put a colon after the parameter name, then the type.
def greet_player(name: str):
print(f"Welcome, {name}!")
When a function has multiple parameters, each one can have its own type hint:
def add_gold(current_gold: int, found_gold: int):
return current_gold + found_gold
While adding a type hint to a variable declaration like:
character_health: float = 72.5
is considered a bit redundant due to type inference, adding type hints to function parameters is not redundant. If you don't add them, your tooling won't know what types the function expects, which makes autocomplete and error checking less effective.
Hover your cursor over the status variable. See how the tooltip can show you that it's a string? That's what makes type hinting useful! Note that name, level, health, and has_magic are all "unknown" because Python can't infer function parameter types without hints.
Fantasy Quest's character status function already works, but its parameters aren't labeled yet. Add type hints to the parameters of get_character_status.
Don't change the function body.