Multiple Ways To Print Blank Line in Python

Introduction

Sometimes, while programming in Python, we come to a situation where we want to print the data in a new line, a blank line between two lines, or print the data in the same line without using the newline. This article will help you understand the concept of printing the blank line between the two lines in depth with all the suggested ways.

What is an empty line?

An empty line is a blank line that has lots of spaces and lots of tabs in them. We can also say an empty line is a blank line with space between the two lines.

Multiple Ways to Print a Blank line in Python

There are many such ways to print the blank line in Python. We will be discussing all the ways to print the blank line. Let us start by taking all the ways with the help of examples:

1. Using print() function

In this example, we will use the print() function to print the empty line between the two given lines. Let us look at the example for a better understanding of the concept:

#using print() for empty lines

str = 'latracal Solutions'
s = 'is the best website'

print(str)
print()
print(s)

Output:

latracal Solutions

is the best website

Explanation:

  • Firstly, we have taken two input strings in the variable str and s.
  • Then, we have printed the first string str.
  • After that, we have applied the print().
  • At last, we have printed the second string.
  • We can see the output with one blank line in between the two given strings.

2. Using the Print() function with single quotes to print blank line in Python

In this example, we will use print() with single quotes to print the empty line between the two given lines. Let us look at the example for a better understanding of the concept:

#using print() with single quotes for empty lines

str = 'latracal'
s = 'solutions'

print(str)
print('')
print(s)

Output:

latracal

solutions

Explanation:

  • Firstly, we have taken two input strings in the variable str and s.
  • Then, we have printed the first string str.
  • After that, we have applied the print() with single quotes inside them.
  • At last, we have printed the second string.
  • We can see the output with one blank line in between the two given strings.

3. Using print() function with double quotes

In this example, we will use print() with double quotes to print the empty line between the two given lines. Let us look at the example for a better understanding of the concept:

#using print() with double quotes for empty lines

str = 'latracal'
s = 'solutions'

print(str)
print("")
print(s)

Output:

latracal

solutions

Explanation:

  • Firstly, we have taken two input strings in the variable str and s.
  • Then, we have printed the first string str.
  • After that, we have applied the print() with double quotes inside them.
  • At last, we have printed the second string.
  • We can see the output with one blank line in between the two given strings.

Also Read: How to Remove Quotes From a String in Python

4. Using Print() function with a newline character To Print Blank Line In Python

In this example, we will be using print() with a newline character in it to print the empty line between the two given lines. The newline character is denoted by n. The newline character can be written in single and double quotes according to your preference. Let us look at the example for a better understanding of the concept:

#using print() with newline character for empty lines

str = 'latracal'
s = 'solutions'

print(str,"\n")
print(s)

Output:

latracal 

solutions

Explanation:

  • Firstly, we have taken two input strings in the variable str and s.
  • Then, we have printed the first string str.
  • After that, we applied the print() with a newline character inside them.
  • We can print the newline character with singles as well as double quotes.
  • At last, we have printed the second string.
  • We can see the output with one blank line in between the two given strings.

5. Printing multiple blank lines

A. Using the multiplication operator

In this example, we will use the print() function with the newline character and * operator, which can produce multiple blank lines between the two given lines. The newline character is denoted by n. Let us look at the example for a better understanding of the concept:

#using print() with newline character with * for multiple empty lines

str = 'latracal'
s = 'solutions'

print(str)
print(5 * "\n")
print(s)

Output:

latracal






solutions

Explanation:

  • Firstly, we have taken two input strings in the variable str and s.
  • Then, we have printed the first string str.
  • After that, we applied the print() with a newline character and * operator inside it.
  • We can print the newline character with singles as well as double quotes. Both will work the same.
  • At last, we have printed the second string.
  • We can see the output with multiple blank lines in between the two given strings.

B. Using multiple times newline characters to print blank line in Python

In this example, we will use the print() function with the newline character multiple times to produce blank lines between the two given lines. The newline character is denoted by n. Let us look at the example for a better understanding of the concept:

#using print() with newline character writing multiple times to print multiple empty lines

str = 'latracal'
s = 'solutions'

print(str)
print("\n\n\n\n\n\n")
print(s)

Output:

latracal





solutions

Explanation:

  • Firstly, we have taken two input strings in the variable str and s.
  • Then, we have printed the first string str.
  • After that, we applied the print() with a newline character writing multiple times inside it.
  • We can print the newline character with single and double quotes. Both will work the same.
  • At last, we have printed the second string s.
  • We can see the output with multiple blank lines in between the two given strings

Conclusion

In this tutorial, we have learned about how to print the blank spaces between the two lines in python in many ways. we have also learned to print multiple blank lines between two lines. All the ways are discussed with the help of examples and they are explained in detail. You can choose any of the ways to print blank lines in python according to your choice.

However, if you have any doubts or questions, do let me know in the comment section below. I will try to help you as soon as possible.

Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mis
Mis
2 years ago

How to print two strings line after line in python with a single command?

Pratik Kinage
Admin
1 year ago
Reply to  Mis

You mean print("\nLine1\nLine2") ?