Saturday, March 27, 2021

Python Pool: Multiple Ways To Print Blank Line in Python

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.

Multiple Ways to Print a Blank line in Python

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.

The post Multiple Ways To Print Blank Line in Python appeared first on Python Pool.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...