Well,
before we get to why, we must know what an escape sequence is in Python. In
python the backslash is “\” is what is known as the escape and the sequence
represents certain whitespace character. In detail we use it because Escape
sequence is two or more than two character which mostly begin with escape
character (\). This escape character gives special instruction to the
interpreter in python to perform some function or command to be precise.
Here is list of examples gotten from the source below. It
helps us understand how each sequence works and benefits every user.
|
Escape
Sequence
|
Description
|
Example
|
Output
|
|
\\
|
Prints Backslash
|
print "\\"
|
\
|
|
\`
|
Prints single-quote
|
print "\'"
|
'
|
|
\"
|
Pirnts double quote
|
print
"\""
|
"
|
|
\a
|
ASCII bell makes
ringing the bell alert sounds ( eg. xterm )
|
print "\a"
|
N/A
|
|
\b
|
ASCII backspace ( BS
) removes previous character
|
print "ab"
+ "\b" + "c"
|
ac
|
|
\f
|
ASCII formfeed ( FF
)
|
print
"hello\fworld"
|
hello
world |
|
\n
|
ASCII linefeed ( LF
)
|
print
"hello\nworld"
|
hello
world |
|
\N{name}
|
Prints a character
from the Unicode database
|
print
u"\N{DAGGER}"
|
†
|
|
\r
|
ASCII carriage
return (CR). Moves all characters after ( CR ) the the beginning of the line
while overriding same number of characters moved.
|
print
"123456\rXX_XX"
|
XX_XX6
|
|
\t
|
ASCII horizontal tab
(TAB). Prints TAB
|
print "\t*
hello"
|
*
hello
|
|
\t
|
ASCII vertical tab
(VT).
|
N/A
|
N/A
|
|
\uxxxx
|
Prints 16-bit hex
value Unicode character
|
print
u"\u041b"
|
Л
|
|
\Uxxxxxxxx
|
Prints 32-bit hex
value Unicode character
|
print
u"\U000001a9"
|
Æ©
|
|
\ooo
|
Prints character
based on its octal value
|
print
"\043"
|
#
|
|
\xhh
|
Prints character
based on its hex value
|
print
"\x23"
|
#
|
|
LinuxConfig.org
|
|||