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 - In Python, empty strings are treated as "Falsy". So, we can use this for checking if a string is empty or not.
🌐
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.
🌐
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.
🌐
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 in a new tab) Sentry BlogLogging in Python: A Developer’s Guide (opens in a new tab)
🌐
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".
🌐
Better Stack
betterstack.com › community › questions › how-to-check-if-string-is-empty-in-python
How to check if the string is empty in Python? | Better Stack Community
To check if a string is empty in Python, you can use the len() function. For example: ... Alternatively, you can use the bool() function to check if the string is empty. An empty string is considered to be False, and all other strings are considered ...
🌐
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?
In this approach, we are going to use the string, which contains the whitespace, which is not empty, and apply this method to remove the whitespace characters from the string, making the string falsy. Following is the syntax for the Python strip() function - ... Following is the example, where ...
Find elsewhere
🌐
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.
🌐
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 - To check if the string is empty in Python, we shall be implementing the len() method in Python. As the string with whitespace is not considered empty, it will give a numerical value for the number of whitespaces that have been used in the string.
🌐
Squash
squash.io › how-to-check-for-an-empty-string-in-python
How to Check for an Empty String in Python
We use an if-else statement with the not operator to check if string is empty. If it is, we print "The string is empty"; otherwise, we print "The string is not empty". Related Article: Python Command Line Arguments: How to Use Them
🌐
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.
🌐
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)
🌐
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 - The simplest, and most Pythonic, way of checking if a string is empty in Python is to simply use an if-else block with the not keyword.
🌐
STechies
stechies.com › check-python-string-empty
Python: Check if String is Empty
# Initializing an empty string Str = '' # Using not operator if not Str: print ("String is empty") else: print ("String is not empty") ... In the above example, we created an empty string ‘Str’. Then we used a not operator to reverse the ...
🌐
AskPython
askpython.com › home › 4 methods to check whether a string is empty in python
4 Methods to Check Whether a String Is Empty in Python - AskPython
February 27, 2022 - str1 = "" str2 = " " if(not (str1 and not str1.isspace())): print ("Yes the string is empty") else : print ("No the string is not empty") if(not (str2 and not str2.isspace())): print ("Yes the string is empty") else : print ("No the string is ...
🌐
Python Pool
pythonpool.com › home › blog › 7 quick ways to check if string is empty in python
7 Quick Ways to Check If String is Empty in Python - Python Pool
May 4, 2023 - Not operator is used to perform the same task as of len() function. The empty string is always equivalent to False in Python. If we want to check if the string is empty or not, we can check it with the help of not operator.
🌐
Studytonight
studytonight.com › post › how-to-check-for-an-empty-string
How to check if string is empty in Python? - Studytonight
May 3, 2023 - 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.