How to Check if a String Is Empty or None in Python
A value your script needs, such as a setting or a field from a form, can be missing as an empty string "" or as None. Python treats both as false in a condition, so a single if not value: catches either.
Syntax
if not <value>:
# <value> is "", None or another false value
| Part | What it does |
|---|---|
not <value> | True when <value> counts as false, such as "" or None. |
if ...: | Runs the indented block when the test is True. |
The Python documentation on truth value testing lists the built-in objects considered false, among them "constants defined to be false: None and False" and "empty sequences and collections: '', (), [], {}, set(), range(0)".
The Example
The example runs three values through one check: a name, an empty string and None.
Prerequisites
- uv and Python. This guide uses uv 0.13.10 with Python 3.15.2.
Step 1: Write the Check
Create a file named main.py:

def describe(value):
if not value:
return "empty or missing"
return f"has text: {value}"
print(describe("Ada"))
print(describe(""))
print(describe(None))
Step 2: Run It
uv run python main.py
has text: Ada
empty or missing
empty or missing

not value was True for both "" and None, so one test handled both. The command is the same in zsh, bash and PowerShell.
What About Spaces?
A string of spaces isn't empty, so it counts as true and passes the check: bool(" ") is True. When spaces should count as missing, strip them first, and test for None before calling a string method:
if value is None or not value.strip():
...
value is None is tested first, so value.strip() only runs on a real string.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Calling value.strip() when value may be None | AttributeError: 'NoneType' object has no attribute 'strip' | Test value is None first |
Using if not value for numbers | 0 is false too, so a real 0 counts as missing | Test numbers with value is None |
Expecting " " to count as empty | It's true, because it isn't empty | Check not value.strip() |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A blank field passes the check | It holds spaces | Strip before testing |
AttributeError: 'NoneType' object has no attribute … | A string method ran on None | Check for None before calling it |
FAQ
Is the string "0" false?
No. Only the empty string is a false string; "0", "False" and " " are all true.
How do I check for None only?
Use value is None. It's True only for None, not for "".
Conclusion
if not value: catches both "" and None in one test, because both are false. Strip the string first when blank strings should count as missing too.
Additional Resources
- Truth value testing, in the Python documentation.
- str.strip(), in the Python documentation.
