How To Print New Line In Python?

New Line is a term used to describe jumping into the next or new line in a text or string. Newline specifies the end of the current line and called the end of the line in some programming languages. Newline can be used to set the end of the current text or show text in an elegant way without filling the screen completely.

New Line Characters

Python uses the /n as a new line character which consist of slash and n character. The new line characters or expression can be used everywhere inside a string data or literal like start of the string, middle of the string or end of the string.

"This is the website\n"
"This is the \n website"
"\nThis is the website"

New Line In Terminal Output For Python Interactive Shell

Python provides an interactive shell in order to run and execute Python scripts. This interactive shell provides an interactive command-line wherein every statement new line is added automatically like below. But if you look following example the new line inside a string literal is not added to the interactive shell. If we create a string variable named s and put a new line while printing this s variable the new line printed too.

>>> "I like"+""
>>> "I like "+" "
'I like '
>>> "I like "+"\n "
'I like \n '
>>> s = "I like "+"\n "
>>> s
'I like \n '
>>> print(s)
I like 

New Line In A File

One of the most popular use cases for the new line is writing into the files. Especially text, code, script, or command files contains multiple lines and every line is created with the new line. The file.write() method is used to write new content to the opened file. By default, this method does not add the end of line automatically. So we should add a new line by using the write() method like below.

file.write("I like")
file.write("I like")
file.write("I like \")

The file content will be like below.

I like PythonTect.comI like
I like

New Line with print() Method

The print() is the one of the most used method which will print given text or content or data into the standard output. Generally the standard output will be a terminal or shell or a log file. The print() method provide

Print Without New Line

The print() method adds a new line at the end of the given string automatically and implicitly. Take a look to the following examples where every print() method has a new line.


The output will be like below where every print() method parameter is printed with a new line.


We can disable automatic new lines by using the print() method end parameter by setting empty string or whatever we want. By default the end parameter gets \n new line and this is added to the end of the content in every print() method. We can also add other characters to the end of the print() content by using the end parameter.

print("I like")

print("I like " , end="")

print("" , end="")

The output will be like below.

I like
I like

Leave a Comment