When a Variable Has No Value
Sometimes in programming, we create a variable before we know what its value will be.
For example, in World of Software Engineering, a player might not currently have an enemy selected.
We can represent “nothing” using a special value called None.
For example, in World of Software Engineering, a player might not currently have an enemy selected.
We can represent “nothing” using a special value called None.
Here is how we create an empty variable:
It means the variable currently has no value assigned.
enemy = NoneThis does NOT mean the word "None".
It means the variable currently has no value assigned.
Important difference:
They are completely different things.
enemy = NoneThis is a real None-type value.
enemy = "None"This is just text that says “None”.
They are completely different things.
Why does this matter?
Programs often check if something exists before using it.
For example:
Programs often check if something exists before using it.
For example:
print(enemy is None)This will return True if enemy is empty.
Your Task:
Create a variable called enemy and set it to None.
Do not modify the print statement.
Create a variable called enemy and set it to None.
Do not modify the print statement.
Create an empty variable
# create the empty "enemy" variable here # don't edit anything under this comment line print(enemy is None)