📚

Escape Characters

Special Characters in Strings

Sometimes you need characters that you can't just type — like a line break in the middle of a string, or a tab for indentation. Python uses escape sequences starting with a backslash

\\
:

EscapeWhat it producesExample
\\n
New line
"Line 1\\nLine 2"
\\t
Tab (indent)
"Name:\\tAlice"
\\\\"
Double quote
"She said \\\\"Hi\\\\""
\\\\'
Single quote
'It\\\\'s fine'
\\\\\\\\
Backslash
"C:\\\\Users"
print("First\nSecond")    # Two lines
print("Name:\tAlice")      # Tab-indented
💡

💡 The

\\n
(newline) is by far the most commonly used escape character. You'll see it everywhere in Python!

main.pySandbox
main.py