Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python,包括字符串前后的反斜杠_Python_Python 3.x - Fatal编程技术网

python,包括字符串前后的反斜杠

python,包括字符串前后的反斜杠,python,python-3.x,Python,Python 3.x,我的最终目标是在运行以下代码时获得[\'2\',\'3\': results=['2','3'] launchArgs=[] for thing in results: thing="'"+thing+"'" THING=thing.replace("'","\'") launchArgs.append(THING) print(launchArgs) 然而,我越来越 ["\'2\'", "\'3\'"] 我应该怎么做?“[\'{}\',\'{}\].”格式(2,3)

我的最终目标是在运行以下代码时获得[\'2\',\'3\':

results=['2','3']
launchArgs=[]
for thing in results:
    thing="'"+thing+"'"
    THING=thing.replace("'","\'")
    launchArgs.append(THING)
print(launchArgs)
然而,我越来越

["\'2\'", "\'3\'"]
我应该怎么做?

“[\'{}\',\'{}\].”格式(2,3)
我想你应该把括号放在“”,因为我从来没有见过这个[\'\'],只在字符串“[\'\']”里面。

这是管道的要求。你显示的输出是一样的。双引号仅表示您正在打印字符串。如果您试图将带引号的参数传递给某个命令,则不需要转义字符。。。请给出一个“管道”的例子,如果实际需要的是一个列表,而不是一个字符串,该怎么办?\'2\'看起来像是转义,你是否尝试输入[2,3],“2”,“3”]或['2',3'],[“\'2\\'”,“\'3\'”?对不起,我的错,我想你应该试试这个:[“\'2\\'3\'”]-一个反斜杠用于转义,第三个反斜杠用于转义。试试这个这不是我的问题。。。我想你应该在上面评论一下,问这个问题到底想问什么对不起,我的错。不管怎么说,我觉得有点不对劲,我没有看到钥匙