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 !!

Was this post helpful?

Join 7000+ Fellow Programmers

Subscribe to get new post notifications, industry updates, best practices, and much more. Directly into your inbox, for free.

Leave a Comment

HowToDoInJava

A blog about Java and its related technologies, the best practices, algorithms, interview questions, scripting languages, and Python.