5

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?

0

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.