

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Variables
incomplete
2: Variables Vary
incomplete
3: Math
incomplete
4: Negative Numbers
incomplete
5: Comments
incomplete
6: Variable Names
incomplete
7: Basic Variable Types
incomplete
8: F-Strings in Python
incomplete
9: NoneType Variables
incomplete
10: NoneType Quiz
incomplete
11: Dynamic Typing
incomplete
12: Math With Strings
incomplete
13: Multi-Variable Declaration
incomplete
14: Boots
incomplete
15: Spellbook
incomplete
16: Character Report
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Click to play video
As we mentioned in the last exercise, the None keyword is used to define an "empty" variable.
So when would you use it? One use case is to represent that a value hasn't been determined yet, for example, an uncaptured input. Maybe your program is waiting for a user to enter their name. You might start with a variable:
username = None
Then later in the code, once the user has entered their name, you can assign it to the username variable:
username = input("What's your name? ")
Remember, it's crucial to recognize that None is not the same as the string "None". They look the same when printed to the console, but they are different data types. If you use "None" instead of None, you will end up with code that looks correct when it's printed but fails the tests. In that case, printing the type would distinguish between the two values.
str_none = "None"
actual_none = None
print(str_none) # None
print(actual_none) # None
print(type(str_none)) # <class 'str'>
print(type(actual_none)) # <class 'NoneType'>