How to Print without New-line in Python?

Python Print without new line

To print without new line in Python, set the parameter, end, of the print() function to empty string.

In this tutorial, we shall go through examples, to print a string, without new line at the end of it, in the standard console output.

Sample Code – Print without new line

Following is the sample code snippet of print() function, that prints the string to console without new line.

print(string, end='')

Example 1: Python Print without New-line

In this example, we will demonstrate how to print without new line and print with new line.

Python Program

#print without new line
print('hello',end='')
print(' world.',end='')
print(' welcome to',end='')
print(' pythonexamples.org')
Run this program

Output

hello world. welcome to pythonexamples.org

Example 1: Python Print Replace New-line at End with Other

You can replace the new-line end character with a string or character of your choice.

In the previous example, we have passed an empty string for named parameter end. Instead of an empty string, pass the ending string or character you require.

In this example, we will demonstrate how to print replace new line end character with a hyphen.

Python Program

print('hello',end='-')
print(' world.',end='+')
print(' welcome to',end='###')
print(' pythonexamples.org', end='\n\n\n')
Run this program

Output

hello- world.+ welcome to### pythonexamples.org

Summary

In this tutorial of Python Examples, we learned how to print a string, without a new line at the end.