Creating an Empty String in Python: Different Methods


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.

https://youtu.be/4HZ-GSueUv4?si=x6hjoKHkf7G0uA-K

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)

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)

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)

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.