In Python, you can use the `print()`
function to print output to the console. By default, the `print()`
function adds a newline character at the end of the output, which means that each time you call `print()`
, the output will be printed on a new line.
If you want to print multiple statements on the same line, you can use the `end`
parameter of the `print()`
function to specify a string that should be printed at the end of the output. By default, the end parameter is set to a newline character, but you can change it to any string you like.
Here’s an example of how to use the `end`
parameter to print multiple statements on the same line:
1 2 | print("Hello", end=' ') print("TecAdmin!") |
This will output the following:
Hello TecAdmin!
As you can see, the two statements are printed on the same line, with a space between them, because we set the end parameter to a space character.
You can also use the `sep`
parameter of the `print()`
function to specify a string that should be used to separate the different arguments passed to `print()`
. For example:
1 | print("Hello", "world!", sep=', ') |
This will output the following:
Hello, world!
I hope this tutorial helps you with a basic understanding of how to print in the same line in Python! Let me know if you have any questions in the comments.