None
- Python course
- Beginner
- Lesson 16/116
- 4 min
Learn the 'no value' state with None.
The None type
None is a special type meaning "no value". It is like null in other languages. It marks that a variable has no value yet:
result = None
if result is None:
print("Not computed yet")None is NOT the same as False. None == False is false. Checking with is None is the right way.
None and falsy
None is a falsy value: if None: does not run. But None == False is still false. None means "no value", not "empty".
data = None
if not data:
print("Empty or None") # runsNone is different from an empty string (""). An empty string is text; None is nothing. Do not confuse them.
Practice Check None
Assign None to result. Then check it with print(result is None).
Starter code
# Define resultSample solution
result = None
print(result is None)Expected output
True
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is the right way to check None?
- if result == None:
- if result is None: Correct answer
- if result = None:
- if None(result):
Explanation: is None checks identity, the right way.
2 Assign None to result
result = ____
print(result is None)
result = None
print(result is None)
Explanation: result = None means no value.
3 Match the types
| Term | Meaning |
|---|---|
None |
No value |
True |
True |
False |
False |
"" |
Empty string |