Python Program to Print Output Without a Newline – 2024

Hey guys, in this blog we will see a Python Program to Print Output Without a Newline.

Using end keyword

# print each statement on a new line
print("I love blogs")
print("from machinelearningprojects.net")

# new line
print()

# print both the statements on a single line
print("I love blogs", end=" ")
print("from machinelearningprojects.net")

Output

I love blogs
from machinelearningprojects.net

I love blogs from machinelearningprojects.net
  • First of all, we have printed ‘I love blogs’.
  • In the second line, we have printed ‘from machinelearningprojects.net’.
  • Then we printed an empty line.
  • In the 4th example, we have again printed ‘I love blogs’ but this time we have set the end parameter to ‘ ‘ (space). By default, this is set to ‘\n’ which means a new line. That’s why in the 2 example print statement went into the second line due to the end=’\n’ of the first print statement.
  • The last print statement will come just after the ‘I love blogs’.

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 514

Leave a Reply

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