How to print an empty line in Python

An empty line is a blank line that is composed of spaces, tab spaces. In this tutorial, you will be learning how to print an empty line in Python programming language, Python provides various alternative methods in printing an empty line unlike other languages, we shall see the different methods in which an empty line can be printed. The following methods shown below is with respect to python3.x.

Method 1: Using the print function – Print an empty line in Python

print()

The code given above can further be understood easier with an example given below:

Example:

print("Hello World")
print()
print("I am a Python Programmer")
Output:

Hello World

I am a Python Programmer

Method 2: print function with single quotes (‘ ‘) – Print an empty line in Python

print('')

The code given above can further be understood easier with an example given below:

Example:

print("Hello World")
print('')
print("I am a Python Programmer")
Output:

Hello World

I am a Python Programmer

 

Method 3: print function with double quotes (“”) – Print an empty line in Python

print("")

The code given above can further be understood easier with an example given below:

Example:

print("Hello World")
print("")
print("I am a Python Programmer")
Output:

Hello World

I am a Python Programmer

Learn these too:

Method 4: print function with newline character (\n)

print('\n')

Description:

From the above code the newline character is enclosed within single quotes (‘ ‘) but can also be enclosed within the double quotes(” “). Whereas the above code will result in an error if the newline character is neither enclosed with the single quotes(‘ ‘) nor the double quotes(” “).

The code given above can further be understood easier with an example given below:

Example:

print("Hello World\n")

print("I am a Python Programmer")
Output:

Hello World

I am a Python Programmer

 

Thus, the above methods can give us different ways to allow us to print an empty string.

Also read:

Leave a Reply

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