How to Print on Same Line in Python: Simple Guide
print() function with the end='' parameter to avoid moving to a new line. For example, print('Hello', end='') prints without adding a newline, so the next print continues on the same line.Syntax
The print() function normally ends with a newline, moving the cursor to the next line. To print on the same line, use the end parameter to change what is printed at the end. By default, end='\n' (newline). Setting end='' prints nothing after the output, so the next print stays on the same line.
print(value, end=''): printsvaluewithout moving to a new line.- You can set
endto any string, like a space' 'to separate outputs on the same line.
print('Hello', end='') print(' World!')
Example
This example shows printing multiple values on the same line by setting end=' ' to add a space instead of a newline. It prints numbers 1 to 5 on one line separated by spaces.
for i in range(1, 6): print(i, end=' ') print('Done')
Common Pitfalls
A common mistake is forgetting to set end='' or end=' ', so each print() outputs on a new line by default. Another is mixing print() with input() without flushing output, which can cause unexpected line breaks.
Also, using commas in print() adds spaces but still ends with a newline unless end is set.
print('Hello') print('World') # Prints on two lines # Correct way: print('Hello', end=' ') print('World') # Prints on same line
Quick Reference
Use this quick guide to remember how to print on the same line:
| Usage | Description | Example |
|---|---|---|
| Default print | Prints with newline | print('Hi') |
| Print same line | Set end to empty string | print('Hi', end='') |
| Print with space | Set end to space | print('Hi', end=' ') |
| Print multiple values | Separate by commas, ends with newline | print('Hi', 'there') |