Index
Introduction
An escape sequence is a special character used in the form of backslash() followed by a character that is required. These characters are used to represent whitespace. Whitespace gives characters like space, tab, form-feed, and vertical tab.
Common Escape Sequences in Python
Escape Sequence | Description |
---|---|
\\ | Backslash (\ ) |
\' | Single quote (' ) |
\" | Double quote (" ) |
\n | Newline |
\t | Tab |
\r | Carriage return |
\b | Backspace |
\f | Form feed |
\ooo | Character with octal value ooo |
\xhh | Character with hex value hh |
Examples
New line:
Backslash:
Space:
Backspace:
oss: remove’s the space between to words
Hexa value:
oss: it’s used to convert hexa value into a string
Octal value:
Raw Strings
In Python, you can create raw strings by prefixing the string with the letter r or R. In raw strings, backslashes are treated as literal characters and not as escape characters in Python.