Print blank line in Python

Print blank line in Python

The print() function can display some message or output in Python. Sometimes, the final result can be congested and unclear due to a need to display multiple or long outputs.

What is a blank line in Python?

We can use a blank line to display the final output in a clean, understandable way. A blank line is an empty line between two messages. The \n character produces a newline in Python.

We will understand how to print blank lines in this tutorial.

Ways to print blank line in Python

Using an empty print() function

In Python, multiple uses of the print() function can display the output in different lines.

See the following example.

Output:

This is the first message
This is the second message

This is because the print() function has a parameter end, which is \n by default. The end parameter adds this character to the end of the output. So, a blank line can be displayed using an empty print() function.

For example,

Output:

This is the first message

This is the second message

Using the print() function with newline character

In the print() function, we can add an empty line between messages using the newline character \n within the function. We will use the newline character twice to add a blank line between two messages.

For example,

Output:

This is the first message

This is the second message

Using the print() function with an empty string

We can specify an empty string using single quotes in the print() function to display a blank line.

See the code below.

Output:

This is the first message

This is the second message

Similarly, we can specify an empty string using double quotes in the print() function to display a blank line.

For example,

Output:

This is the first message

This is the second message

Using the print() function with the sep parameter

The sep parameter in the print() function specifies the character that separates two values in Python. Its default value is blank whitespace.

If we change this to two newline characters \n, we can add a blank line between values.

See the code below.

Output:

This is the first message

This is the second message

Ways to print multiple blank lines in Python

Using the print() function with multiple newline characters

As discussed earlier, we can use the newline character \n to add a blank line between messages in Python. We can use it multiple times to display multiple blank lines.

For example,

This is the first message

This is the second message

Using the print() function with multiplication operator

Another way to achieve this is by using the multiplication operator *. We multiply the newline character \n the required number of times to display multiple blank lines.

For example,

Output:

This is the first message

This is the second message

Conclusion

We have explained and discussed different methods to print blank line in Python in this article. Such blank lines can help in displaying a clean output that is readable and understandable.

Related Posts

  • How to comment out multiple lines in python
    16 October

    How to comment out multiple lines in python

    Table of ContentsMultiple Line Comments in PythonUsing the # characterUsing triple quotesUsing IDEs and Text Editors In this article, we will see about how to comment out multiple lines in python. The concept of comments is present in most programming languages. We use comments for documentation purposes. The compiler ignores them, but the user can […]

  • Get variable name as String in Python
    01 October

    How to get variable name as String in Python

    Table of ContentsWhat are variable names in Python?How to get a variable name as a string in Python?In Python 2.xIn Python 3.x In Python, there are several ways to convert a string to a variable name, but the reverse process is not exactly utilized so often in the programming world. This article focuses on how […]

  • Python print percent sign
    30 September

    Print percentage sign in python

    Table of ContentsIntroductionPrint the Percentage Sign in PythonUsing the %% characterUsing the format() functionUsing the f-string Introduction In this tutorial, we will see how to print percentage sign in python. The modulus operator (%) or the percentage sign has multiple usages in Python. We use this operator to calculate the remainder for the division between […]

  • 17 September

    Write list to CSV in Python

    Table of ContentsUsing the write() function to write a list to a CSV fileUsing the csv module to write a list to a CSV fileUsing the numpy module to write a list to a CSV fileUsing the numpy.savetxt() function to write a list to a CSV fileUsing the numpy.tofile() function to write a list to […]

  • Python add commas to number
    11 September

    Python add commas to number

    Table of ContentsUsing the format() function to add commas to numbers in PythonUsing the fstrings to add commas to numbers in PythonUsing the regular expressions to add commas to numbers in PythonUsing the locale module to add commas to numbers in Python Python allows us to format values to get the final result in our […]

  • 10 September

    Change the font size of title in Matplotlib

    In Python, there are a lot of libraries that are used for data visualization. One of the libraries is the Matplotlib library. The Matplotlib library is a very good library when it comes to data visualisation in python. With the help of this library, many types of graphs and visual representations of the data can […]

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.