Skip to content

How to print in the same line in Python | Example code

  • by

If you are print multiple times then it will not print output in the same line in Python. Because print() function is used to print the output and By default, it jumps to the newline to printing the next statement.

See the below example.

print("Hello")
print("world")
print("!")

Output:

How to print in the same line in Python

To print in the same line write a complete statement in a single print() function in Python.

print("Hello world !")

Output: Hello world !

Use end keyword

By adding the ‘ ‘ two single quotation marks you create the space between the two words, Hello and World, (Hello’ ‘World’) – I believe this is called a “blank string”.

print('Hello', end= ' ')
print('World')

Output: Hello World

Print in the same line in for loop

The Python print() function has an argument called end, which prevents jump into the newline. Example use the end keyword in python. SAMPLE Of “end=” being used to remove the “newline” character.

list1 = [10, 11, 12, 13, 14, 15]
for i in list1:
    print(i, end=" ")

Output:

Print in the same line in for loop

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading