When an 'r' or 'R' prefix is present,
a character following a backslash is
included in the string without change,
and all backslashes are left in the
string. For example, the string
literal r"\n" consists of two
characters: a backslash and a
lowercase 'n'. String quotes can be
escaped with a backslash, but the
backslash remains in the string; for
example, r"\"" is a valid string
literal consisting of two characters:
a backslash and a double quote; r"\"
is not a valid string literal (even a
raw string cannot end in an odd number
of backslashes). Specifically, a raw
string cannot end in a single
backslash (since the backslash would
escape the following quote character).
Note also that a single backslash
followed by a newline is interpreted
as those two characters as part of the
string, not as a line continuation.
r
表示该字符串将被视为原始字符串,这意味着将忽略所有转义码例如:
'\n'
将被视为换行符,而r'\n'
将被视为字符\
,后跟n
资料来源:Python string literals
这意味着逃避不会被翻译。例如:
是一个带反斜杠的字符串,后跟字母
n
。(如果没有r
,这将是一条新线。)b
代表字节字符串,在Python3中使用,默认情况下字符串为Unicode。在Python2.x中,默认情况下字符串是字节字符串,您可以使用u
来表示Unicode相关问题 更多 >
编程相关推荐