Skip to content
Home » How to Print Without a Newline in Python

How to Print Without a Newline in Python

In this article let’s learn about how to Print Without a Newline in Python. The built-in Python print() function is used to print the specified text inside the command prompt. The newline character is added at the end by default when using Python’s print command.

For Example:

Python3

print("geeks")
print("Similargeeks")

Output:

geeks
Similargeeks

However, there are situations where we don’t want to go to next line but want to print on the same line.  So what can we do?

For Example:

Input :

print("geeks") print("similargeeks")


Output :

geeks similargeeks

Input:

a = ['similar','geeks',3, 4]
print(a)


Output : [‘similar’, ‘geeks’, 3, 4]

The solution depends totally on the python version you are using. 

Python 2.x

Using for loop

# Python 2 code for printing on the same line printing
print("geeks"),
print("similargeeks")
 
# array
s = [1, 2, 3, 4, 5]
 
# printing array elements in the same line
for i in range(4):
    print(s,[i]),

Output:

geeks similargeeks
1 2 3 4 5

Python 3.x

With Python 3 , the end= option has been added as a second parameter for print(). This parameter handles eliminating the newline that is added by default in print().

print("Hi!! ", end="")
print("Welcome to Similar Geeks")

Also Read:
How to Get Python dictionary keys as a List
How to Save List to CSV in Python