jak10101
jak10101

Reputation: 19

Python 2.7.6 String Literal error with Quotations in Quotations

In the function

print 'He said, "\"She\'s pretty"\'

I am getting an error that says "There's an error in your program: EOL while scanning string literal" How do I fix this?

Upvotes: 0

Views: 137

Answers (2)

user2357112
user2357112

Reputation: 280778

print 'He said, "She\'s pretty."'

In a single-quoted string, you should only escape single quotes that you don't want to be treated as the end of the string. The single quote at the end shouldn't be escaped, since it marks the end of the string.

(Also, I've ended the sentence with a period. You can take that out if you want.)

Upvotes: 0

mhlester
mhlester

Reputation: 23231

No need to escape the double quotes, but the big problem is the escape of the single quote at the end, when you want to end the string

print 'He said, "She\'s pretty"'

Upvotes: 1

Related Questions