Skip to content

Python create empty string | Example code

  • by

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.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