How to Check Whether a Value Is None in Python with is None
Python uses None for "no value here": an option nobody set, a search that found nothing, a function that returns nothing. Before you use a value that might be None, check it with is None. This guide shows the check, and its opposite, on Python 3.15.2.
Syntax
if <value> is None:
<code to run when there is no value>
if <value> is not None:
<code to run when there is a value>
| Part | What it means |
|---|---|
<value> | Any variable or expression |
is None | True only when the value is the None object itself |
is not None | The opposite: True for every other value |
The Python documentation describes None as "An object frequently used to represent the absence of a value" and adds that it "is the sole instance of the NoneType type." Because there is only one None, the identity operator is is the right test: "x is y is true if and only if x and y are the same object." Python's style guide, PEP 8, says: "Comparisons to singletons like None should always be done with is or is not, never the equality operators."
The Example
A person has no middle name, stored as None, and the nickname Sam. The script prints a line for the missing one and for the one that's there.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
middle_name = None
nickname = "Sam"
if middle_name is None:
print("No middle name")
if nickname is not None:
print(f"Nickname: {nickname}")

Step 2: Run It
uv run python none_check.py
No middle name
Nickname: Sam

middle_name is None was True, so the first message printed. nickname is not None was True too, so the second one printed with the nickname. The command works unchanged in PowerShell.
Step 3: See Why if not value Is a Different Test
if not value: looks shorter, but it asks a different question: whether the value counts as false. None does, and so do 0, "" and []. A count of zero is a real value, not a missing one:
count = 0
if not count:
print("Treated as missing")
if count is None:
print("Missing")
else:
print(f"Count: {count}")
uv run python not_zero.py
Treated as missing
Count: 0

if not count took the zero for a missing value. count is None was False, so the script printed the real count, 0. PEP 8 warns about exactly this: "beware of writing if x when you really mean if x is not None".
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
if value == None: | It works for plain values, but == asks the object, and PEP 8 says never to use it for None | if value is None: |
if not value: when 0 or "" are real values | They're treated as missing, as Step 3 shows | if value is None: |
Using the value before the check, such as len(name) | TypeError: object of type 'NoneType' has no len() when it's None | Check is None first |
FAQ
Is is not None the same as not value is None?
They give the same answer, but PEP 8 asks for is not, which reads as plain English.
Can I use is to compare numbers or text?
No. is asks whether two names point to the very same object, not whether the values are equal. Use == for values, and keep is for None.
Conclusion
middle_name is None was True for None, and nickname is not None was True for "Sam". if not count took a count of 0 for a missing value, while count is None didn't, which is why is None is the test for "no value".
Additional Resources
- None — the built-in constant.
- Identity comparisons — what
isandis notcompare. - PEP 8: Programming recommendations — the style rule for comparing with
None.
