Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteFor a value you know is a Python string, use not value to check whether it is exactly empty, or not value.strip() to treat whitespace-only strings as blank. None and NaN are different kinds of values, so handle them with their own checks.
Check whether a string is exactly empty
An empty string has zero characters. Python strings are false-valued when empty, so a concise check is:
value = ""
if not value:
print("empty string")
This works when value is known to be a string. It does not consider spaces or tabs empty: " " contains characters and is truth-valued.
Python’s truth-value rules describe which objects evaluate as false, including empty strings.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →#1 Best Overall
Check whether a string is blank or whitespace-only
If strings containing only surrounding whitespace should count as blank, call strip() before testing:
value = " tn"
if not value.strip():
print("empty or whitespace-only string")
str.strip() returns a copy with leading and trailing whitespace removed. If nothing remains, the string is empty or whitespace-only under that method’s definition. See Python’s string method documentation.
Rank #2
Handle None separately
None is not a string; it is Python’s singleton object for the absence of a value. Check it with identity comparison, then check strings only when appropriate:
if value is None:
print("missing value")
elif isinstance(value, str) and not value.strip():
print("empty or blank string")
The is None check avoids confusing a missing value with an empty string. Python documents None as a singleton constant in its built-in constants reference.
Check NaN with a NaN predicate
NaN (“not a number”) is a floating-point value, not a string. Equality is not a reliable way to detect it: NaN compares unequal to itself, so a comparison with float("nan") will not identify it. For a compatible numeric scalar, use math.isnan():
import math
value = float("nan")
if math.isnan(value):
print("NaN")
For NumPy numeric values, use numpy.isnan() (commonly imported as np.isnan()). NumPy documents the behavior of IEEE 754 special floating-point values and its isnan function.
Choose a check for the input you actually have
| Input and meaning | Use | What the check returns or means |
|---|---|---|
| Known string; only zero characters count | not value |
True for "", false for whitespace-only strings. |
| Known string; whitespace-only also counts as blank | not value.strip() |
True when stripping whitespace leaves no characters. |
| Value may be absent | value is None |
Checks specifically for Python’s None singleton. |
| Compatible numeric scalar may be NaN | math.isnan(value) |
Checks for NaN; requires a compatible numeric value. |
| NumPy value or array | np.isnan(value) |
Checks NumPy numeric values; array input produces array-like results. |
| Pandas-supported scalar or tabular data may be missing | pd.isna(value) |
Recognizes missing values such as None, NaN, and NaT. Scalar input yields a scalar result; array-like input yields array-like booleans. |
For mixed or tabular data already handled with pandas, pd.isna() is the library-level missing-value check:
import pandas as pd
pd.isna(None) # True
pd.isna(float("nan")) # True
For a Series or DataFrame, pd.isna() returns corresponding array-like booleans, not one ordinary Boolean. Do not use that result directly in a single if condition; reduce it according to the question you mean to ask, such as whether any entries are missing or all entries are missing. See the pandas.isna documentation.
Best Value
Avoid the wrong generic check
Do not call .strip() on an unknown value unless you have established it is a string or chosen what to do with other types. A number, None, or another object may not have that method.
Likewise, if not value: checks general truthiness, not specifically whether a value is a missing string. It also treats values such as numeric zero, False, and empty containers as false. Use it for a string only when the input is actually a string; otherwise use a type-appropriate check.
Quick Recap
Quick decision rule
- Known string, exact emptiness:
not s. - Known string, blank includes whitespace-only:
not s.strip(). - Possible missing Python value: check
s is None. - Possible numeric NaN: use
math.isnan(),np.isnan(), or, for pandas-supported missing values,pd.isna(). - Array or Series: account for the array-like result instead of expecting one Boolean.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




