Python – Create an empty string

Create an empty string

To create an empty string in Python, we can specify no value enclosed in the single quotes, no value enclosed in double quotes, or no argument passed to str() builtin function.

Examples

1. Create an empty string using single quotes

In the following program, we create an empty string using single quotes, and store the value in x.

Python Program

x = ''
print('x :', x)
Run Code Copy

Output

x : 

2. Create an empty string using double quotes

In the following program, we create empty string using double quotes.

Python Program

x = ""
print('x :', x)
Run Code Copy

Output

x : 

3. Create an empty string using str()

In the following program, we create empty string using str() builtin function. Pass no value as argument to str() function. The function returns an empty string.

Python Program

x = str()
print('x :', x)
Run Code Copy

Output

x : 

Summary

In this tutorial of Python Examples, we learned how to create an empty string in different ways, with the help of well detailed examples.

Related Tutorials

Code copied to clipboard successfully 👍