Guide Python Beginner

5.8 NoneType

Python's None singleton, why it's distinct from 0 and an empty string, and why you should always compare to None with is, not ==.

2 min read

None Object

What Is It?

Python’s singleton “no value” object — there is exactly one None in a running program, and its type is NoneType.

Why Is It Used?

To explicitly represent the deliberate absence of a value, distinct from any actual data value like 0 or an empty string.

>>> n = None
>>> type(n)
<class 'NoneType'>
>>> n is None    # always compare to None with 'is', not '=='
True

None vs 0 vs Empty String

What Is the Difference?

All three are “falsy” in a boolean context, but they mean different things. 0 is a valid number, "" is a valid (if empty) string — None means no value was ever set at all. Conflating them is a common source of bugs (e.g. treating a legitimate 0 balance as “missing data”).

>>> bool(None), bool(0), bool("")
(False, False, False)    # all falsy, but NOT equal to each other
>>> None == 0, None == ""
(False, False)

Quick Interview Answer

None is Python’s singleton for ’no value’ — there’s exactly one None object in a running program, of type NoneType. It’s falsy, but it isn’t 0 or \"\" — those are valid, real values. Always compare to None with is, not ==, since is checks identity against that one singleton object rather than relying on equality logic.”

Common Mistakes

  • Comparing to None with == instead of isis is both faster and the semantically correct check for a singleton.
  • Treating None, 0, and "" as interchangeable “empty” values — they’re all falsy but represent genuinely different things.
  • Using a mutable default of None incorrectly, or conversely forgetting None is the standard sentinel for “no default was given” (see 5.15 Common Mistakes for the mutable-default-argument bug).

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form