

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
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
To add a type hint to a variable declaration, put a colon after the variable name, then the type. This comes before the equals sign and the value:
character_name: str = "Sir Galahad"
character_level: int = 7
character_health: float = 72.5
has_magic: bool = True
The values work the exact same way they did before. In fact, when it comes to simple variable declarations like this, you don't actually need the hint. In this example:
character_health = 72.5
Because character_health is assigned a value of 72.5, your tooling can infer that it's a float. That said, if you also want to see the type name, you can optionally add it.
Fantasy Quest's character setup code works, but the variable types are wrong! Notice that our code editor's tooling gives us nice red squiggles to show us the mistakes.
Fix the type hints for each variable.
character_name should be a strcharacter_level should be an intcharacter_health should be a floathas_magic should be a boolDon't change the values. Just fix the type hints, as the tests will fail without them.