Python Print without Newline

In this post, we will see how to print without Newline in Python.

In python, when you use two print statements consecutively, it will print in different line.

Output:

πŸ’» Awesome Tech Resources:
  • Looking for βš’οΈ tech jobs? Go to our job portal.
  • Looking for tech events? Go to tech events πŸ—“οΈ Calendar.️
Hello world
from Java2blog

As expected, we got Hello world and from Java2blog

If you want to print these two print statements in the same line, you can do it in different ways.

💡 Did you know?

If you are using python 2, then you can simply put comma(,) to print statements in same line.

Using print statement

You can use end='$delimiter' with print statements and it will print string with delimiter.

Print with space

You can use end=' ' for printing statements separated by space.

Output:

Hello world from Java2blog

Print with comma(,)

You can use end=',' for printing statements separated by comma.

Output:

Hello world,from Java2blog

Using sys library

You can also import sys library and use sys.stdout.write() to print on same line.

Output:

Hello worldfrom Java2blog

Printing without newline is very useful while printing using a loop. If you don’t want to print each element in an individual line, you can use end=' ' with print statement to print on the same line.

Output:

India China Russia France

As you can see, all the elements are printed on same line separated by space(' ')

That’s all about Python Print without Newline.

Related Posts

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.