Python Program - Print Output Without a Newline

‮w//:sptth‬ww.theitroad.com

To print output without a newline in Python, we can use the end parameter of the print() function. By default, end is set to '\n' (newline), but we can set it to an empty string to avoid the newline character.

Here's an example program that demonstrates how to print output without a newline:

# print numbers from 1 to 10 on the same line
for i in range(1, 11):
    print(i, end=' ')

Output:

1 2 3 4 5 6 7 8 9 10

As you can see, all the numbers are printed on the same line separated by a space. The space is added by specifying end=' ' instead of the default end='\n'.