Empty strings are "falsy" (python 2 or python 3 reference), which means they are considered false in a Boolean context, so you can just do this:

if not myString:

This is the preferred way if you know that your variable is a string. If your variable could also be some other type then you should use:

if myString == "":

See the documentation on Truth Value Testing for other values that are false in Boolean contexts.

Answer from Andrew Clark on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-check-if-string-is-empty-or-not
Check if String is Empty or Not - Python - GeeksforGeeks
July 11, 2025 - So, we can use this for checking if a string is empty or not. ... The string is empty. Explanation: "not s" negates the boolean value of s, if it's empty then it's boolean quivalent to False and its negation would be True.
🌐
Sentry
sentry.io › sentry answers › python › check if a string is empty in python
Check if a string is empty in Python | Sentry
if my_string.strip() == "": print("my_string is an empty string!") else: print("my_string is not an empty string!") Sentry BlogPython Performance Testing: A Comprehensive Guide (opens in a new tab) Syntax.fmListen to the Syntax Podcast (opens ...
🌐
TutorialsPoint
tutorialspoint.com › what-is-the-most-elegant-way-to-check-if-the-string-is-empty-in-python
What is the most elegant way to check if the string is empty in Python?
Let's look at the following example, where we are going to use the basic way to check whether the string is empty or not. str1 = "" if not str1: print("It Is Empty.") else: print("It Is Not Empty.") ... The string is empty. The Python len() function is used to determine the length of an object ...
🌐
PythonHow
pythonhow.com › how › check-if-a-string-is-empty
Here is how to check if a string is empty in Python
The 'not' operator returns True if the string is empty and False if it is not. ... In Python, you can check if a string is empty by using the 'not' operator as shown in the code above.
🌐
Wyzant
wyzant.com › resources › ask an expert
Most elegant way to check if the string is empty in Python? | Wyzant Ask An Expert
May 22, 2019 - Python's developers chose to make the truthiness property of strings a function of their length. Taking bool() on a zero-length string evaluates to False. The empty string is the only possible zero-length string. All other strings return True. An if statement in Python must have a Boolean argument.
Find elsewhere
🌐
Scaler
scaler.com › home › topics › program to check if string is empty in python
Program to Check if String is Empty in Python - Scaler Topics
January 11, 2023 - Be it the len() method or the not operator where it considers the whitespace as an element of the string. As strings in Python cannot be modified once they’re created, hence it is useful to check if a string is empty or not.
🌐
Stack Abuse
stackabuse.com › how-to-check-if-a-string-is-empty-or-none-in-python
How to Check if a String is Empty or None in Python
June 5, 2023 - We'll use an or operator to check both conditions at once: s = "" # Try also with s = None if s is None or s == "": print("String is empty or None") else: print("String is not empty and not None") Advice: Find out more about the or operator in Python by reading our "Guide to the Python or Operator".
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › check if string is empty or not in python
Check if String is Empty or Not in Python - Spark By {Examples}
May 21, 2024 - You can use the if not my_string: syntax to check if a string is empty. This evaluates to True if the string is empty. Are there other ways to check for an empty string? There are additional ways to check for an empty string in Python.
🌐
Quora
quora.com › How-do-I-check-if-the-string-is-empty-in-Python
How to check if the string is empty in Python - Quora
Answer (1 of 15): You can check it with a very simple if execution. Let us say, if you want to check pure empty string (must not contain even whitespaces), then you can do just like below: [code]if not string: print("Empty") [/code]Or, if you want to consider string with no character (but may ...
🌐
Tutor Python
tutorpython.com › check-if-string-is-empty-in-python
How to Handle or Check if String is empty in Python
December 25, 2023 - Let’s delve into this technique with a concise Python code example: my_string = "" if len(my_string) == 0: print("The string is empty") else: print("The string is not empty") The check for emptiness we use the character count.
🌐
Python Examples
pythonexamples.org › python-check-if-string-is-empty
Python - How to check if string is Empty?
To check if given string is empty, you can either use the string variable as a condition along with NOT logical operator, or compare the given string with an empty string "" using Equal-to comparison operator.
🌐
Syntax Scenarios
syntaxscenarios.com › python › check-if-a-string-is-empty
How to Check if a String is Empty in Python? – Syntax Scenarios
An empty string is considered False in Python. This allows you to directly check if a string is empty by simply evaluating its truth value using the not operator.
🌐
Reddit
reddit.com › r/learnpython › empty string returns true upon checking if its contained in a non empty string
r/learnpython on Reddit: empty string returns True upon checking if its contained in a non empty string
June 7, 2025 -

This code is meant to count all the words that have the expression "di" but with the text "imagina." the final answer is 1.

texto = 'imagina.'
cl = 0
flag_di = False
answer = 0
previous = ''

for car in texto:
    if car != ' ' and car != '.':
        cl += 1
        
        
        if car in 'iI' and previous in 'dD':
            flag_di = True
            
        previous = car
    
    else:
        if car == ' ' or car == '.':
            if flag_di:
                answer += 1
                
            cl = 0
            flag_di = False
            previous = ''
    
print(answer)
🌐
30 Seconds of Code
30secondsofcode.org › home › python › string is empty
How can I check if a string is empty in Python? - 30 seconds of code
August 5, 2022 - Thus, simply using the not operator, you can check if a string is empty. empty_string = '' non_empty_string = 'Hello' not empty_string # True not non_empty_string # False · While this method works in most cases, you may also need to check if ...
🌐
datagy
datagy.io › home › python posts › python strings › how to check if a string is empty in python
How to Check if a String is Empty in Python • datagy
December 16, 2022 - To get semantics out of the way, ... Pythonic, way of checking if a string is empty in Python is to simply use an if-else block with the not keyword....
🌐
PythonHello
pythonhello.com › problems › string › how-to-check-if-string-is-empty
Checking if a string is empty in Python
string = "" if len(string) == 0: print("The string is empty") else: print("The string is not empty") This will print "The string is empty", because the length of the empty string is 0. Another way to check if a string is empty is to use the ...
🌐
Studytonight
studytonight.com › post › how-to-check-for-an-empty-string
How to check if string is empty in Python? - Studytonight
May 3, 2023 - It is denoted by two quotes with nothing in between them: "". You can check if a string is empty in Python using the not operator, which returns True if the string is empty and False otherwise.