【发布时间】:2013-03-24 18:09:54
【问题描述】:
我正在使用 python 与操作系统进行通信。
我需要创建一个如下形式的字符串:
string = "done('1') && done('2')"
请注意,我的字符串中必须有双引号,但我不知道该怎么做,因为双引号在 python 中用于定义字符串。
然后我做类似的事情:
os.system(string)
但系统只会读取包含双引号和单引号的字符串。
我试过了:
>>> s = '"done('1') && done('2')"'
File "<stdin>", line 1
s = '"done('1') && done('2')"'
^
SyntaxError: invalid syntax
我也尝试了此处建议的三引号,但出现错误:
>>> s = """"done('1') && done('2')""""
File "<stdin>", line 1
s = """"done('1') && done('2')""""
^
SyntaxError: EOL while scanning string literal
How to store a string containing both single quote( ' ) and double quote( " ) in python
【问题讨论】:
标签: python