Escape character \ can escape a lot of character, such as \ n for newline, \ t for a tab character \ itself have escaped, so the character is represented \\ \.
>>>print('I\'m ok.') I'm ok. >>> print('I\'m learning\nPython.') I'm learning Python. >>> print('\\\n\\') \ \
If the string there are many characters need to be escaped, we need to add a lot \
, in order to simplify, Python also allows r''
representation ''
default does not escape the string inside, you can see for yourself:
>>> print('\\\t\\') \ \ >>> print(r'\\\t\\') \\\t\\
If the internal string has a lot of line breaks, with \n
write one line is not good reading, in order to simplify, Python allows '''...'''
format represents a number of lines, you can see for yourself:
>>> print('''line1 ... line2 ... line3''') line1 line2 line3
Escape character
|
significance
|
ASCII value (decimal)
|
\a
|
Bell (BEL)
|
007
|
\b
|
Backspace (BS), the current position to the previous column
|
008
|
\f
|
Feed (FF), the current position to the beginning of the page
|
012
|
\n
|
Line feed (LF), the current position to the beginning of the next line
|
010
|
\r
|
A carriage return (CR), the current position to the beginning of the line
|
013
|
\t
|
Horizontal tab (the HT) (TAB jumps to the next position)
|
009
|
\ v
|
Vertical tabulation (VT)
|
011
|
\\
|
Represent a backslash character '\'
|
092
|
\'
|
On behalf of a single quote (apostrophe) character
|
039
|
\"
|
It represents a double quote character
|
034
|
\? | On behalf of a question mark | 063 |
\0
|
Null character (NUL)
|
000
|
\ddd
|
Any character 1-3 octal number represented
|
Three octal
|
\ socialization
|
Hexadecimal character represents any
|
Hex
|