Skip to content

Python test empty string | Example code

  • by

Python Empty strings are “falsy” (python 2 or python 3 references), which means they are considered false in a Boolean context, so you have to just do this:

if not myString:

Example code test empty string in python

Simple python example code. The most elegant way would probably be to simply check if its true or falsy,

string = ""
if not string:
    print("Empty String!")

Output:

Python test empty string

Do comment if you have any doubts and suggestions on this Python string topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading