Loading...

Python None

None, an empty text, and the number 0 are three different values. print(None) writes None. print("") writes a blank line, because nothing sits between the quotes. print(0) writes 0. None means nothing is stored. It is not a blank line, and it is not zero.

None, a blank line, then 0

python
print(None)
print("")
print(0)

The three lines are None, then a blank line, then 0. A condition treats both None and an empty text as false, but the screen does not show them the same way. bool(None) writes False. That only answers the condition. It does not turn None into empty text or into 0.

A name can hold nothing, then something

guest = None stores no value under the name guest. print(guest) writes None. A later line, guest = "lida", replaces that. print(guest) writes lida. None does not stay beside the new value.

Nothing stored, then lida

python
guest = None
print(guest)
guest = "lida"
print(guest)

The first print is None. The second print is lida.

Quotes make text, and a small n stops the program

print("None") writes the letters None. That line looks the same as print(None). You cannot tell them apart from the output alone. The quotes in the code are what make it text. none, with a small n, is not this value. Python looks for a stored name, does not find one, and the program stops. None starts with a capital N.

Same letters on the screen can still be different values. Read the code, not only the output.

📊 Four ways that are easy to mix up

In the code On the screen What it is
None None nothing stored
"None" None text
"" a blank line empty text
0 0 the number zero

The next page changes one kind into another

This page does not compare two values, choose a branch, or join two conditions. The next page turns text into a number, or a number into text. None is neither text nor a number. You do not convert it here.

Say these yourself

  1. print(None) writes None. print("") writes a blank line. print(0) writes 0.
  2. bool(None) writes False, and None stays None.
  3. guest = "lida" replaces a stored None.
  4. "None" in quotes is text. none with a small n stops the program.
  5. The next page turns one kind of value into another.

Easy to misread

  • Reading a blank line as None
  • Reading 0 as None
  • Treating "None" as no stored value because the screen matches
  • Writing none with a small n
  • Trying to turn None into a number on this page

Keep

None means nothing is stored. The first letter is a capital N.
print(None) writes None. print("") writes a blank line. print(0) writes 0.
bool(None) writes False. None is still not empty text and not zero.
A later line can replace None with a real value.
Quotes make the text None. A small n stops the program.
The next page turns text into a number, or a number into text.

🧠 Test Your Knowledge

Ready to Start

Test Your Knowledge

Challenge yourself with this interactive quiz and see how well you understand the topic

❓
5
Questions
🎯
70%
To Pass
♾️
∞
Time
🔄
∞
Attempts

📝 Instructions

  • Read each question carefully
  • Select the best answer for each question
  • You can retake the quiz as many times as you want
  • Your progress will be shown at the top