Check a String is Empty in Python

  • Post category:String

In this article, you will see how to check a string is empty in Python. An empty string is a string that contains no characters. You can use the not operator to check if a string is empty.

Step 1: Create an empty string

str = ""
print("str = ", str)
print("str type = ", type(str))

Step 2: Check if a string is empty

if not str:
    print("Empty")
else:
    print("Not Empty")

Output:

str =  
str type =  <class 'str'>
Empty

Free resources to learn advanced skills: AiHints and CodeAllow