How to Print Without Newline in Python: Simple Guide
In Python, you can print without a newline by using the
print() function with the end parameter set to an empty string like print('text', end=''). This tells Python not to add the default newline after printing.Syntax
The basic syntax to print without a newline uses the print() function with the end parameter.
print(value, end=''): Printsvalueand does not move to a new line.- The
endparameter controls what is printed after the value; by default, it is'\n'(newline). - Setting
end=''means nothing extra is printed after the value.
python
print('Hello', end='') print('World')
Output
HelloWorld
Example
This example shows how to print multiple words on the same line without spaces or newlines between them by setting end=''. It demonstrates how the output stays on one line.
python
print('Python', end='') print(' is') print(' fun!')
Output
Python is fun!
Common Pitfalls
A common mistake is forgetting to set end='', which causes each print() to add a newline by default. Another is expecting end=' ' to remove newlines completely; it only adds a space instead.
Also, using commas inside print() adds spaces automatically, which might confuse output formatting.
python
print('Hello') print('World') # Correct way without newline print('Hello', end='') print('World')
Output
Hello
World
HelloWorld
Quick Reference
| Usage | Description | Example |
|---|---|---|
| Default print | Prints with newline | print('Hi') # Adds newline |
| Print without newline | Use end='' to avoid newline | print('Hi', end='') |
| Print with space instead of newline | Use end=' ' to add space | print('Hi', end=' ') |
| Print multiple values | Comma adds space between values | print('Hi', 'there') |
Key Takeaways
Use print(value, end='') to print without a newline in Python.
The end parameter controls what is printed after the output; default is newline.
For spaces instead of newlines, use end=' '.
Remember that commas in print add spaces automatically.
Without setting end, print adds a newline after each call.