What does empty print () do 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:

  • How to print string and int in the same line in Python
  • How to escape from \n newline character in python

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:

  • How to remove \n from list elements in Python – last character new line

  • Introduction
  • What is an empty line?
  • Multiple Ways to Print a Blank line in Python
    • 1. Using print[] function
    • 2. Using Print[] function with single quotes to print blank line in python
    • 3. Using print[] function with double quotes
    • 4. Using Print[] function with a newline character To Print Blank Line In Python
    • 5. Printing multiple blank lines
  • Conclusion

Introduction

Sometimes, while programming in Python, we came 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 in between the two lines in deep 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 tab in them. We can also say an empty line is a blank line that has a space between the two lines.

There are many such ways present 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 be using the print[] function to print the empty line between the two give 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 s.
  • We can see the output with one blank line in between the two given strings.

2. Using Print[] function with single quotes to print blank line in python

In this example, we will be using 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 s.
  • 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 be using 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 s.
  • 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 having a newline character in them 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 have applied the print[] with a newline character inside them.
  • We can print the newline character with single as well as the double-quotes.
  • At last, we have printed the second string s.
  • We can see the output with one blank line in between the two given strings.

5. Printing multiple blank lines

A. Using multiplication operator

In this example, we will be using the print[] function with the newline character and * operator, who can produce multiple blank lines between the two give 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 have applied the print[] with a newline character and * operator inside it.
  • We can print the newline character with single as well as the 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.

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

In this example, we will be using the print[] function with the newline character multiple times to produce multiple blank lines between the two give 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 have applied the print[] with a newline character writing multiple times inside it.
  • we can print the newline character with single as well as the 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.

How do you print an empty line in Python?

Use print[] without any arguments to print a blank line Call print[] without any arguments to output a blank line.

What is print [] in Python?

The print[] function prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen.

How do you check for blank lines in Python?

Use an if-statement to check if a line is empty Call file. readlines[] to return all lines in file . Use a for-loop to iterate through each line. For each line, use an if-statement with the syntax if line == "\n" to check if line contains only a newline character.

What do you mean by blank line in Python?

An empty line is a blank line that is composed of spaces, tab spaces.

Chủ Đề