All IT Courses 50% Off
Python Tutorials

Python Print WITHOUT Newline

with Examples

The Print is a built-in function in Python that is used to display text on the console or output screen. The default Print function outputs the text with endline. In this tutorial, we will have a look at different versions of print statements.

Working of Normal print() function

The print function takes a string or variable as input. As shown in the example below. The normal print function adds an end line at the end of the line.

print(“Hello World”)
print(“Simple print adds an end line.”)
Python Print WITHOUT Newline

How to print without a newline in Python?

We just need to add an end parameter at the end of the print statement as shown in the image below.

print(“Hello World” , end=’ ‘)
print(“Simple print adds an end line.”)
Python Print WITHOUT Newline

We can also end our line with a dot(.)

All IT Courses 50% Off
print(“Hello World ” , end=’.’)
print(“Simple print adds an end line.”)
Python Print WITHOUT Newline

Using Python sys module

There is another way to print on the console using the sys library. When using the sys library function write it does not add end line.

Python Print WITHOUT Newline
import sys

sys.stdout.write(“Hello World “)
sys.stdout.write(“Welcome to h2kinfosys website”)

Using print() to print a list without a newline

If we simple use for loop to print the elements of the list the following will be the output.

colors = [“Red”, “Green”, “Blue”, “Yellow”, “Brown”]for i in colors:
print(i)
Python Print WITHOUT Newline

For printing all the list items in a single line we simply need to add the end parameter.

colors = [“Red”, “Green”, “Blue”, “Yellow”, “Brown”]for i in colors:
print(i, end=’ ‘)
Python Print WITHOUT Newline
Facebook Comments

One Comment

  1. Pingback: How To Print Without Newline In Python #2023 Updated Information

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button