Python · Fundamentals & Gotchas

None vs False vs 0

Easynonefalsezerotruthinessbool

Interview question

What is the difference between None, False, and 0?

How to answer

The short answer

They are three different objects with different meanings, even though all are falsy in boolean context.

ValueTypeMeaning
NoneNoneType singletonAbsence of a value / null
FalseboolBoolean false
0intNumeric zero

Because they are all falsy, if not x cannot tell them apart. Use explicit checks.

Python
print(None == False)   # False
print(None == 0)       # False
print(False == 0)      # True  (bool is a subclass of int!)
print(False is 0)      # False
print(isinstance(False, int))  # True

def lookup(name):
    data = {"empty": "", "zero": 0, "missing": None}
    return data.get(name)  # None if key absent OR value stored as None

# Bad: collapses many cases
value = lookup("zero")
if not value:
    print("missing-or-empty-or-zero")

# Better
value = lookup("zero")
if value is None:
    print("none")
elif value == 0:
    print("zero")

Interview tip: Mention that bool subclasses int (True == 1, False == 0) and always recommend is None for null checks.

Lock it in with a real drill

You remember an answer longer once you have used it. Try a hands-on problem on this concept.

Open related drill