Select to view content in your preferred language

What does the \newline escape sequence mean in python?

06-17-2022 02:43 AM
New Contributor II

In the Python manual, I found the sequence \newline in a list of escape sequences. This article from Scaler demonstrated to me that it does not represent itself but is transformed into another character or set of characters that, like newline, may be difficult or impossible to describe directly.

I'm curious how and why it's used. This appears to be translated as 'n' + 'ewline' in my interpreter:

>>> print('\newline')

0 Kudos
2 Replies
Occasional Contributor

It does almost what it says it does.  The \n is the escape sequence for printing a new line in a text string.  The rest of the string is what is to be printed

print ("\newline')


 Lets not forget the venerable \r for carriage return.  There are a few more shown here,



0 Kudos
Regular Contributor II

A backslash means the next character is special.

\n means newline

\t means tab

\\ means \ so for example, "C:\\Program Files" will be interpreted to mean "C:\Program Files".