Python print() Without Newline (on Same Line)

By default, Python print() method adds a new line character (\n) at the end of printed output on the screen. That is why all print() statements display the output in a new line on the screen.

To print the objects in the same line in Python, we can follow given approaches:

1. Print Without New Line in Python 3

Use the end keyword argument in the print() statment. By default, the value of end is '\n' new line character. We have to change the default new line character with another character, e.g. a space character.

Example 1: Print strings in the Same Line with the space between two objects

print("A", end = ' ')
print("B", end = ' ')
print("C", end = ' ')
print("D", end = '\n')

Program output.

A B C D

Example 2: Printing without the space between two objects

The space character is optional. If we do not want to add any separator between the objects then use the empty string.

print("A", end = '')
print("B", end = '')
print("C", end = '')
print("B", end = '\n')

Program output.

ABCD

2. Print Without New Line in Python 2

In Python 2, printing objects in same line is rather easy. We just need to add a comma (',') character between the two print() statements.

print "A",
print "B",
print "C",
print "D"

Program output.

A B C D

Happy Learning !!

Leave a Reply

0 Comments
Inline Feedbacks
View all comments

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.

Our Blogs

REST API Tutorial