How to Print Without Newline in Python

When writing code in Python, the print statement automatically adds a newline character at the end. This can be problematic when you want to output multiple items on the same line. To print without a newline, use the argument “end” in the print statement and set it to an empty string.

Example:

print("Item 1", end="")
print("Item 2", end="")

This will output: “Item 1Item 2”

You can also specify other characters as the end argument, such as a space or tab.

Example:

print("Item 1", end=" ")
print("Item 2", end="\t")

This will output: “Item 1 Item 2 “

By using the “end” argument, you can have more control over the formatting of your output in Python.

Leave a Comment