Lesson 3 of 6 · Numbers, Strings and Operators · 2 min read · Updated

True, False and None

What Python treats as true, what it treats as false, and the value that means nothing.

True and False are the two bool values — note the capital letters. But every value in Python can stand in a condition, and Python decides whether it counts as true.

python
print(bool(0), bool(42))
print(bool(""), bool("hi"))
print(bool([]), bool([0]))
print(bool(None))
Output
False True
False True
False True
False

The rule is short: zero, empty and None are false; everything else is true. An empty string, an empty list, an empty dictionary — all false. A list holding a single 0 is not empty, so it is true.

python
name = ""
if name:
    print("Hello,", name)
else:
    print("No name given")
Output
No name given

Note

if name: is the Python way to write if name != "":, and if items: means "if the list is not empty". Experienced Python code uses this everywhere, so it is worth recognising.

None: no value yet

python
winner = None
print(winner)
print(type(winner))
if winner is None:
    print("No winner yet")
Output
None
<class 'NoneType'>
No winner yet

None means "nothing here", which is different from 0 or an empty string. A function that does not return anything gives back None — you will see that in the Functions topic.

Which value counts as true in an if?

Try this now

  1. Ask for a name; if the user just presses Enter, print "Guest" instead.
  2. Predict bool(" ") (a single space), then check it.

Create a free account to save your progress, or sign in.