To initialize an empty string in Python, Just create a variable and don’t assign any character or even no space. This means assign “” 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")
Do comment if you have any doubts and suggestions on this Python string topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.