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 snippet

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

print(string, end='')

Examples

1. 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 Code Copy

Output

hello world. welcome to pythonexamples.org

2. Override trailing end line

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 Code Copy

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.

Code copied to clipboard successfully 👍