Skip to the content.

Check If a String is Empty

A string can be checked if it’s empty or not by following ways -

Simple Way

my_var = ""
if my_var == "":
    print("Variable is empty!")
    print("Variable is not empty!")

Here we just compare the variable to an empty string.

Advanced Way

my_var = ""
if my_var:
    print("Variable is not empty!") # True when a non-empty string is found
    print("Variable is empty!") # True when an empty string is found

Source: StackOverFlow