Python: String Escape Sequence

By Xah Lee. Date: . Last updated: .

What is Escape Sequence

A String Escape Sequence is a character sequence starting with backslash, inside String, to represent a character.

For example, \n means linebreak.

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

List of Escape Sequence

\'
APOSTROPHE
\"
Double quote
\\
Backslash
\a
ASCII Bell.
\b
ASCII Backspace
\f
ASCII Formfeed
\n
ASCII Linefeed
\r
ASCII Carriage Return
\t
ASCII Horizontal Tab
\ooo
ASCII Character ID in 3 octal digits.
\xhh
ASCII Character ID in 2 Hexadecimal digits.
\uxxxx

Character with Unicode Code Point in 4 Hexadecimal digits.

\Uxxxxxxxx
Character with Unicode Code Point in 6 Hexadecimal digits.
\v
ASCII Vertical Tab
\N{name}
Unicode character named name. [see Unicode: Character Set, Encoding, UTF-8, Code Point]

Python, String