in python how to print in same line ?

Published on Aug. 22, 2023, 12:15 p.m.

There are several ways to print output on the same line in Python. Here are a few:

  1. Using end parameter of the print() function:
print("Hello", end=" ")
print("world!")

This will output “Hello world!” on the same line, with a space between the words.
2. Using a comma between values in a single print():

print("Hello", "world!")

This will output “Hello world!” on the same line, with a space between the words.
3. Using string concatenation:

print("Hello " + "world!")

This will also output “Hello world!” on the same line, with a space between the words.

Note that all of these methods use the print() function, which by default ends with a newline character. By using the end parameter or a comma, you can override the default behavior and output multiple values on the same line.

I hope this helps! Let me know if you have any further questions.

Tags:

related content