How to print multiple print statements in one line in Python?

In Python, you can use the “end” parameter of the print function to have multiple prints on the same line.

By default, the end parameter of the print function has a value of \n, which means a new line is created after printing. Setting the end parameter’s value to an empty string ” allows the output of multiple print functions to be printed on the same line.

Here is an example code:

print('Hello', end=' ')
print('World')

The output result is:

Hello World

In the first print function, the end parameter is set as a blank space string ‘ ‘, so that the output of the first print function will not be on a new line. Then in the second print function, the text will be printed directly after the output of the first print function, on the same line.

bannerAds