Python: String Escape Sequence

By Xah Lee. Date: . Last updated: .

What is Escape Sequence

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

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 Codepoint in 4 Hexadecimal digits. 〔see Python: Unicode Escape Sequence
\Uxxxxxxxx
Character with Unicode Codepoint in 6 Hexadecimal digits. 〔see Python: Unicode Escape Sequence
\v
ASCII Vertical Tab
\N{name}
Unicode character named name. 〔see Unicode: Character Set, Encoding, UTF-8, Codepoint

Python, String