Python: String Escape Sequence

By Xah Lee. Date: . Last updated: .

A String Escape Sequence is a special character sequence inside String to represent a character.

For example, \n means linebreak.

# \n means linebreak
x = "A\nB"
print(x)
# A
# B

Here's complete list of escape sequence:

\'
Single quote
\"
Double quote
\\
Backslash
\a
ASCII Bell
\b
ASCII Backspace
\f
ASCII Formfeed
\n
ASCII Linefeed
\r
ASCII Carriage Return
\t
ASCII Horizontal Tab
\ooo
Character with ASCII ID in 3 octal digits.
\xhh
Character with ASCII ID in 2 hexadecimal digits.
\uxxxx
Character with Unicode ID in 4 hexadecimal digits
[see Python: Unicode Escape Sequence]
\Uxxxxxxxx
Character with Unicode ID in 6 hexadecimal digits
[see Python: Unicode Escape Sequence]
\v
ASCII Vertical Tab
\N{name}
Unicode character named name. [see Unicode Basics: Character Set, Encoding, UTF-8, Codepoint]

Python String

Python

Overview

Help

Comment

String

Arithmetic

Boolean

Conditional

Loop, Iteration

Data Structure

Function and Class

Module

Misc

Regex

Text Processing

Web

Misc