Python Escape Characters Table
| Escape Character | Explanation |
|---|---|
\' | Single Quote |
\" | Double Quote |
\n | Newline Character |
\t | Tabular Character |
\b | Backspace Character |
\r | Carriage Return |
\\ | Backslash |
\ | Form Feed |
\ooo | Octal Value |
\xhh | Hex 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