About this question
How can you print output in Python without adding a newline or space? What techniques let you control exactly how text appears on the same line?
How can you print output in Python without adding a newline or space? What techniques let you control exactly how text appears on the same line?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Python Expert
Answered on May 21, 2025
Printing output without a newline or extra space in Python is quite simple once you know the right tricks. By default, the print() function adds a newline at the end, so each call prints on a new line. But sometimes, you want to keep everything on the same line or control spacing precisely.
How to print without a newline:
Use the end parameter of the print() function:
print("Hello", end="")
print("World")This will output:
HelloWorld print("Hello", "World")Outputs:
Hello WorldTo avoid the space, set the sep parameter to an empty string:
print("Hello", "World", sep="")Outputs:
HelloWorldCombining both for full control:
print("Hello", end="")
print("World", sep="")You can also use this approach in loops to print on the same line without newlines or spaces:
for i in range(5):
print(i, end=" ")This prints:
0 1 2 3 4Summary:
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common Python interview questions, answered
Guides, tips and career advice on Python from JanBask experts.
Python How to Become a Python Developer: A Step-by-Step Guide for Beginners
Discover how to become a Python Developer via a practical 7-step guide build projects, maintain clean code, practice daily, and…
Python PCEP Certification Guide: Entry-Level Python Programmer Certification
Explore this PCEP certification guide for insights on cost, exam format, passing score, application, training, and study tips.…
Python Top 50+ Python Projects ideas for Beginners to Advanced
Discover innovative Python project ideas, explore advanced Python projects, and find good Python projects for beginners and…
Python How To Comment Out Multiple Lines In Python Like A Pro
Commenting out code is a common practice among programmers. It allows you to temporarily disable parts of your code without…