How to Put a Line Break in a Python String with \n (Newline)
You can't press Enter in the middle of an ordinary Python string, because the string has to end on the line where it started. To put a line break inside it, you type \n, a backslash and the letter n, and Python turns that into a new line. This guide does it on Python 3.15.2.
Syntax
"<first line>\n<second line>"
| Part | What it means |
|---|---|
<first line> | The text before the line break |
\n | The newline escape sequence: a backslash followed by n. Python stores it as one line-break character |
<second line> | The text that starts on the next line |
The language reference explains that "Inside a string literal, the backslash (\) character introduces an escape sequence, which has special meaning depending on the character after the backslash." Its table lists \n as "ASCII Linefeed (LF)", the character that starts a new line.
The Example
The script prints three things: one string that comes out on two lines, a string with an empty line between two words, and the length of "\n" on its own.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
print("First line\nSecond line")
print("Above\n\nBelow")
print(len("\n"))

"First line\nSecond line"is one string. The\nin the middle marks where the line breaks."Above\n\nBelow"has two line breaks in a row, so the second one starts a line with nothing on it.len("\n")counts the characters in a string that holds only the escape sequence.
Step 2: Run It
uv run python lines.py
First line
Second line
Above
Below
1

The first string came out on two lines, and the second left an empty line between Above and Below. The 1 is the point to notice: you typed two characters, a backslash and an n, but the string holds one, the line break itself. The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Typing a forward slash: "First line/nSecond line" | No line break. Python prints the text as typed: First line/nSecond line | Use a backslash: "First line\nSecond line" |
FAQ
How do I keep \n as two characters?
Put an r in front of the string to make it a raw string. print(r"First line\nSecond line") printed First line\nSecond line, on one line. The language reference says escape sequences are interpreted "Unless an ‘r’ or ‘R’ prefix is present", so in a raw string a backslash stays a backslash.
Which other escape sequences are there?
The escape sequences table in the language reference lists them all, such as \t for a tab, \\ for a backslash and \" for a double quote.
Conclusion
\n inside a string started a new line, \n\n left an empty line, and len("\n") showed that the two characters you type become a single line-break character.
Additional Resources
- Escape sequences — every sequence a backslash can start, and what each one means.
- String and bytes literals — how Python reads the text between quotes.
