Quick answer: Use if not text to detect an ordinary empty string, but call strip() first when whitespace-only input should count as empty. Keep None separate when it means a missing value rather than supplied empty text.

An empty string in Python is a string with zero characters: "". You can check it directly with text == "", or you can rely on Python’s truth testing with if not text.
The official Python documentation covers truth value testing and str.strip().
The right check depends on what you mean by empty. A truly empty string has length zero. A blank string, such as " ", contains whitespace and is not empty until you strip it.
Be explicit in validation code. If whitespace-only input should fail, use strip(). If only a zero-length string should fail, compare directly or use a truth test.
This distinction matters in forms, configuration files, CSV imports, search boxes, and command-line prompts. A user may press space several times and create text that looks empty on screen but still contains characters.
It also matters when None is possible. None means no value was supplied, while "" means a string was supplied with no characters. Treat those cases separately when they have different meaning in your program.
Compare With An Empty String
The most direct check is text == "".
text = ""
if text == "":
print("empty")
else:
print("not empty")
This checks only for a string with zero characters.
It does not treat spaces, tabs, or newlines as empty. That strictness is useful when whitespace has meaning.
Use direct comparison when you want the code to say exactly what it checks. It is slightly more verbose than not text, but very clear for readers.
Use not text
Empty strings are false in Python truth tests.
text = ""
if not text:
print("empty")
else:
print("not empty")
This is concise and idiomatic when you already know the value is a string.
Be careful if the value might be None, 0, an empty list, or another false object. Those also pass a broad not check.
If the input type is uncertain, check that it is a string before using a broad truth test. That prevents unrelated false values from being treated as empty text.
Check For Blank Text
Use strip() when whitespace-only text should count as blank.
text = " \n"
if text.strip() == "":
print("blank")
else:
print("has content")
strip() removes whitespace from both ends before the comparison.
This is common for form fields, command-line input, CSV cells, and other human-entered text.
strip() returns a new string. It does not change the original text object, so assign the cleaned result if you need to reuse it later.
Use len For Explicit Length
len(text) returns the number of characters in the string.
text = ""
if len(text) == 0:
print("length is zero")
else:
print("length is", len(text))
This is more verbose than a truth test, but it can be useful when the length itself appears in an error message.
If you only need to know whether the string is empty, not text or text == "" is usually clearer.
Length checks are still useful when enforcing minimum or maximum lengths. For example, you may first reject empty text and then require at least eight characters.
Filter Empty Strings From A List
A list comprehension can remove empty or blank strings from a sequence.
items = ["red", "", " ", "blue"]
clean_items = [item for item in items if item.strip()]
print(clean_items)
This keeps only strings that have content after whitespace is stripped.
Use this when cleaning user-entered lists, tag inputs, or imported rows where blank cells should be ignored.
If blank entries should be reported instead of removed, keep their positions and return a validation error. Filtering is best when blank items are harmless noise.
Write A Helper For Validation
A helper keeps the rule in one place.
def has_text(value):
return isinstance(value, str) and bool(value.strip())
for value in ["Python", "", " ", None]:
print(value, has_text(value))
This helper accepts only strings with non-whitespace content.
In production code, choose a helper name that states the rule clearly. has_text is different from is_empty, because it rejects whitespace-only strings and non-string input.
Helpers are especially useful when the same validation rule appears in several forms or import steps. Updating one helper is safer than editing the same check in many places.
When writing tests, include empty text, whitespace-only text, normal text, and None. Those four cases cover most mistakes in string validation and make the expected behavior clear.
Also test tabs and newlines when user input comes from pasted text.
For team code, document whether the field accepts whitespace as meaningful content. That small note prevents later cleanup from changing accepted input by accident.
In short, use text == "" for a strict empty string check, not text for concise truth testing, and not text.strip() when blank whitespace should also fail validation.
Empty And Whitespace Are Different
An empty string has length zero and is false in a Boolean context. A string containing spaces, tabs, or line breaks is non-empty until you apply the whitespace policy your input requires. Decide whether surrounding whitespace is meaningful before choosing a check.
def has_text(value):
if value is None:
return False
return bool(value.strip())
print(has_text(""))
print(has_text(" "))
print(has_text(" Python "))
Choose The Check From The Contract
Use if not text: when only the empty string should be false. Use if not text.strip(): when leading and trailing whitespace should not count as content. Use len(text) == 0 when the count itself is part of a larger condition, and use an explicit comparison when teaching a beginner or documenting a strict value check.
For user input, normalize once at the boundary and store the normalized value only when that is appropriate for the domain. Do not strip identifiers, passwords, or formatted text unless the specification says whitespace is insignificant.
Frequently Asked Questions
How do I check if a string is empty in Python?
Use if not text when an ordinary empty string should be false, or compare len(text) == 0 when the length is part of the condition.
How do I treat spaces as an empty string?
Use if not text.strip() when surrounding whitespace should not count as content.
Is None the same as an empty string?
No. None usually represents a missing value, while “” represents supplied text with zero characters.
Should I strip every Python string?
No. Strip only when whitespace is insignificant for that field; passwords, identifiers, and formatted text may need to preserve it.