How to print without a Newline in Python?

In Python whenever you print any statement, a newline is added by default. And, people coming from other languages find it weird and want to know how to avoid this newline. This happens because in Python, Newline is added as a default parameter to print() function. Let’s see some examples below and how can we use print function without newline being added to it.

#Python 3.X
#Using print function in Python
print("Outshine Labs")
print("Python Rocks")

#Default Output of print function
#Outshine Labs
#Python Rocks

Now if you want to use the print function without printing unnecessary newline, you can pass space as the “end” parameter. An example is given below. This solution depends on the python version you are using and works with Python 3. It is recommended that you read more about print functions using the link above.

#Python 3.X
#Using print function without newline in Python
print("Outshine Labs", end=" ")
print("Python Rocks", end=" ")

#Output of print function with custom end parameter
#Outshine Labs Python Rocks

The codes (if any) mentioned in this post can be downloaded from github.com. Share the post with someone you think can benefit from the information

Share this