How To Print Without New Line In Python?

Python provides the print() method in order to print and display specified string or data into the standard output. By default, the print() methods add an end of line or newline character and the cursor jumps to the next line. In some cases, we may want to prevent this and print no newline.

Python3 Print End Parameter

The print() method has a bit changed in Python3 and created as a method rather than a keyword. The print() method generally used with the data and text we want to print but there are some parameters that can be used to change the print() method execution. The end parameter is used to set the last character of the output automatically or implicitly. This parameter is optional and the default value is "\n" which is the end of the line. We can set another value for this parameter which will prevent the end of the line. Even we can set an empty string where there will be no character. In the following example, we will set the end parameter as nothing and no new line will be put.

print("This is not end",end="")

Python2 stdout.write() Method

Python2 print method is implemented as a keyword and does not provide the end parameter to prevent the end of the line. The sys.stdout.write() method can be used to print without a new line. As you expect the write() method is a raw method that is used to put data into the standard output.

print("")

Leave a Comment