Here are three ways to create an empty string in Python:
- Assign to a variable using “single or double quotes.”
- Using the “str()” function.
- Using the “format()” function of an empty string.
Method 1: Using single or double quotes
The quote(“”) is probably the most common and straightforward method to create an empty string. You can use single or double quotes.
Initialize a string containing no characters. This means assigning “” to a variable to initialize an empty string.
empty_string = ""
Print the empty string.
You can see that the output’s second line is empty, meaning it’s an empty string.
Method 2: Using the “str()” function
To create an empty string in Python, you can also use the “str()” function.
empty_string = str() print(empty_string)
Method 3: Using the format() function
You can use the “format()” method to create an empty string in Python.
empty_string = "".format()
To check if the String is empty, use a “not operator”.