How to print without newline in Python?


In python the print statement adds a new line character by default. So when we have multiple print statements the output from each of them is printed in multiple lines as you can see in the example below. Our goal is to print them in a single line and use some special parameters to the print function to achieve that.

Normal Print()

The below example prints multiple statements with new lines in each of them.

Example

print("Apple")
print("Mango")
print("Banana")

Output

Running the above code gives us the following result −

Apple
Mango
Banana

Using end Parameter

We can use the end parameter to use a specific character at the end of the output from each print statement. In the below example we use "," as special character with the end parameter, which will appear at the end of the output of each print statement. The result will not be printed in multiple lines.

Example

print("Apple" , end ="," )
print("Mango", end =",")
print("Banana")

Output

Running the above code gives us the following result −

Apple,Mango,Banana

Updated on: 08-Aug-2019

885 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements