简体   繁体   中英

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?

无需对双引号进行转义,但是最大的问题是,当您结束字符串时,对单引号进行转义

print 'He said, "She\'s pretty"'
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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM