Skip to content

Python initialize empty string | Example code

  • by

To initialize an empty string in Python, Just create a variable and don’t assign any character or even no space. This means assigning “” to a variable to initialize an empty string.

empty_string = ""

Python initialize empty string Example

Simple example code. Initialize and check whether has a string that is empty or not using “Not operator“.

The strings are evaluated to False or True in a Boolean context if they are empty or not. They are not equal to False or True.

str1= ""

if not str1:
    print("String is empty")

Output:

Python initialize 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

Your email address will not be published. Required fields are marked *