Python Escape Characters

Python Escape Characters Table

Escape CharacterExplanation
\'Single Quote
\"Double Quote
\nNewline Character
\tTabular Character
\b Backspace Character
\rCarriage Return
\\Backslash
\Form Feed
\oooOctal Value
\xhhHex Value

Examples

The following examples show the working of the different escape characters in a Python context. We provide the output after each print() statement:

# Single Quote
print('\'')
# '

# Double Quote
print("\"")
# "

# Newline Character
print('Hello\nWorld')
# Hello
# World

# Tabular Character
print('Hello\tWorld')
# Hello	   World

# Backspace Character
print('Backspace: \b')
# Backspace: 

# Carriage Return
print('Hello\rWorld')
# HelloWorld

# Backslash Character
print('Backslash: \\')
# Backslash: \

# Form Feed
print('Hello\
World')
# HelloWorld

# Octal Value
print('\112')
# J

# Hex Value
print('\x44')
# D