Why can't the r "" string of python end with\?

The string starting with r in

python means that the backslash is not escaped, for example:

>>> s = r"asd\a"
>>> s
"asd\\a"

the above results are easy to understand, but not if the backslash appears at the end of the string:

>>> s = r"asd\"
  File "<stdin>", line 1
    s = r"asd\"
              ^
SyntaxError: EOL while scanning string literal

Why is there such a design? Since r means no escape, why is there an error at the end?

Mar.07,2021

I found the previous answer on stack overflow:
python" rel=" nofollow noreferrer "> https://stackoverflow.com/que.

.

"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.."
the above error has been corrected
has been modified:
so I think it may be because in ringing, the 'after the backslash is reserved as a character and is a normal character, so it has lost its function.
or because, for example, r "abc", Mr becomes a "abc" string, and then r is added for processing. If r "backslash", the generated string fails.

Doc. The meaning r "backslash" in Python

Sorry, the backslash is missing. I hope you
python.org/2.0/ref/strings.html" rel=" nofollow noreferrer "> https://docs.python.org/2.0/r.
Doc.python have a description

Menu