python在字符串前后包含反斜杠

时间:2019-10-27 18:33:29

标签: 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\'"]

我该怎么办?

1 个答案:

答案 0 :(得分:0)

“ [\'{} \',\'{} \']”。format(2,3) 我认为您应该将方括号放在“”中,因为我从未见过此[\'\'],仅在字符串“ [\'\']”中