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.

Was this post helpful?


import_contacts

You may also like:

Related Posts

  • 25 June

    Convert Roman Number to Integer in Python

    Table of ContentsHow to Convert Roman Number to Integer in PythonHow to convert roman number to integer in python?Using the if...else statement to convert roman number to integer in Python.Using classes and a dictionary to convert roman number to integer in Python.Using the roman module to convert roman number to integer in Python.ConclusionWas this post […]

  • 11 June

    Remove Single Quotes from String in Python

    Table of ContentsRemove single quotes from string in Python.How to remove single quotes from string in Python?Using the replace() function to remove single quotes from string in Python.Using a for loop to remove single quotes from string in Python.Using the join() function to remove single quotes from string in Python.Using the re module functions to […]

  • 11 June

    Escape Backslash Character in Python

    Table of ContentsEscape backslash character in python.How to use escape backslash character in python?Using the escape backslash character in python to represent whitespace characters.Using the escape backslash character in python to turn special characters into ordinary characters.Using the escape backslash character in f-strings in Python.Using the escape backslash character in raw strings in Python.Was this […]

  • 11 June

    Break out of function in Python

    Table of ContentsBreak out of function in PythonHow to break out of function in Python?Using the return statement to break out of function in PythonUsing the try and except block to break out of function in PythonUsing the sys.exit() function to break out of function in PythonConclusionWas this post helpful? In this post, we will […]

  • 11 June

    Check if Object Is Iterable in Python

    Table of ContentsWhat are iterables in Python?How to check if object is iterable in Python?Using the iter() function to check if object is iterable in PythonUsing the for loop to check if object is iterable in PythonUsing the isinstance() function to check if object is iterable in PythonConclusionWas this post helpful? In this post, we […]

  • 11 June

    Save Numpy Array as Image in Python

    Table of ContentsSave numpy array as image in PythonHow to save numpy array as image in Python?Using the PIL library to save numpy array as image in PythonUsing the matplotlib.image library to save numpy array as image in PythonUsing the opencv library to save numpy array as image in PythonUsing the imageio library to save […]

Leave a Reply

Your email address will not be published.

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.