I'm using python 3.5.1. When I was trying this
print(r'\t\\\')
I got the error: SyntaxError: EOL while scanning string literal. But this one worked well
print(r'\t\\')
Can anyone please explain this?
See the 3.5 docs on String and Bytes literals:
Even in a raw literal, quotes can be escaped with a backslash, but the backslash remains in the result; 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 literal 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 literal, not as a line continuation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With