To print in the same line in Python, you can use the end
parameter of the print()
function. By default, print()
adds a newline character at the end of the output, but you can change this by specifying a different string to be used as the end character.
Here’s an example:
print("Hello", end=" ") print("world!")
Output:
Hello world!
In this example, we use the end=" "
parameter to specify that we want to use a space character as the end character instead of a newline. This causes the second print()
statement to continue on the same line as the first one.
You can use any string as the end character, not just a space. For example, if you wanted to separate the two strings with a comma and a space, you could use:
print("Hello", end=", ") print("world!")
Output:
Hello, world!