0
0
PythonHow-ToBeginner · 3 min read

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=''): Prints value and does not move to a new line.
  • The end parameter 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

UsageDescriptionExample
Default printPrints with newlineprint('Hi') # Adds newline
Print without newlineUse end='' to avoid newlineprint('Hi', end='')
Print with space instead of newlineUse end=' ' to add spaceprint('Hi', end=' ')
Print multiple valuesComma adds space between valuesprint('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.