Python create empty string | Example code

Use "" to create an empty string in Python. There should be no char or whitespace in the string.

empty_string = ""

Python creates an empty string Example

Python simple example code initializes a string containing no characters and no whitespace and checks if String is empty.

To check if the string is empty or not, use a not operator.

empty_string = ""

print(not empty_string);

print(len(empty_string))

Output:

Python create empty string

Another example checks empty string using in if statement.

empty_string = ""

if (not empty_string):
    print("The string is empty")
else:
    print("No it is not empty")

Output:

The string is empty

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

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.