Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing
Back
  1. Home
  2. Interview prep
  3. None vs False vs 0

Python · Fundamentals & Gotchas

None vs False vs 0

Easypython-37
nonefalsezerotruthinessbool

Question

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

Solution

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

| Value | Type | Meaning | | --- | --- | --- | | None | NoneType singleton | Absence of a value / null | | False | bool | Boolean false | | 0 | int | Numeric zero |

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

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.

🎯 Put this concept into practice

Solidify this answer with real hands-on interview drills in the browser studio.

Open related drill →
PreviousNext