Python - Things to know before proceed - Escape Characters/Special Characters Tutorial
The characters which have some unique functionality, such characters are called special character/escape characters. Escape characters are backslash '\' followed by the character you want to insert.
A list of the escape characters are-
- \n - Newline
- \t - Horizontal Tab with 4 spaces
- \v - Vertical Tab
- \' - Single Quotes
- \" - Double Quotes
- \r - Carriage Return
- \\ - Backslash
- \b - Backspace
- \f - Form Feed
- \N - N is number for unicode character
- \NNN - NNN is digits for Octal value
- \xNN - NN is a hex value; \x is used to denote following is a hex value.
- \a - bell sound, actually default chime
Example-
print("New\nLine")
print("Horizontal\tTab\twith\t4\tspaces")
print("Vertical\vTab")
print("Single Quotes\'s")
print("Double Quotes\"s")
print("Carriage\rReturn")
print("Backslash- \\")
print("Back \bSpace")
print("Form \f Feed")
print('\110')
print('\u2713')
print("\U0001F40D")
print("\x69")
Output-
New
Line
Horizontal Tab with 4 spaces
VerticalTab
Single Quotes's
Double Quotes"s
Returnge
Backslash- \
BackSpace
Form Feed
H
✓
?
i