How to Print Without Newline in Python

Sometimes we wants to print string output without newline. Means printing a variable value or statement without going to newline. In Python for printing values print() function is used, which by default ends with newline.

Run below program which prints two string values

print("CrazyGeeks.ORG is one of the best Website ")
print("in the world.")

You will see following output:

CrazyGeeks.ORG is one of the best Website
in the world.

Now run below code you will see a different output:

print("CrazyGeeks.ORG is one of the best Website "),
print("in the world.")

The output should be:

CrazyGeeks.ORG is one of the best Website in the world.

Solution

Method 1: If you see above second program carefully, after first print() function comma (,) is used for skipping newline. So to print without newline you can use comma after print function.

For example:

print("Google is the best "),
print("search engine.") 

The output should be:

Google is the best search engine.

Method 2: Alternatively you can also use second parameter in print() function which is end where you can assign value like end=" "

For example:

print("CrazyGeeks.ORG is one of the best Website ", end =" ") 
print("in the world.") 

The output should be:

CrazyGeeks.ORG is one of the best Website in the world.

Examples

Example 1: using comma

# Python 3 code for printing without newline
  
print("Apple"), 
print("Pineapple") 
  
# array 
a = [1, 2, 3, 4, 5, 6, 7] 
  
# printing a element in same 
# line 
for i in range(7): 
    print(a[i]),  

The output should be:

Apple Pineapple
1 2 3 4 5 6 7

Example 2: using end = " "

# Python 3 code for printing without newline
  
print("Apple", end=" ")
print("Pineapple") 
  
# array 
a = [1, 2, 3, 4, 5, 6, 7] 
  
# printing a element in same 
# line 
for i in range(7): 
    print(a[i],end=" ")  

The output should be:

Apple Pineapple
1 2 3 4 5 6 7