What is Python empty string | Example code

Python string is called an empty string if the string doesn’t have any character, whitespace whatsoever. But if the string has multiple white spaces or single space or tab spaces then it is a blank string.

Example Create and check an empty string in Python.

Simple python example code. In a Boolean context, null / empty strings are false (Falsy). If you use

if not myString:

Code approach

# create empty string
a = ""

# check empty string
if not a:
    print("Empty String")
else:
    print(a)

Output:

Python empty string

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

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

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


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.