字符串下的Python字符串嵌套

时间:2018-08-28 15:16:50

标签: python string text

运行下面的代码行时,得到以下结果:

>>> a = ''' this " is what \"is 'needed' \" Please " '''
' this " is what "is \'needed\' " Please " '

我希望输出为:

' this " is what "is 'needed' " Please " '

问题是'\'取代。 谁能建议解决此问题的方法?

1 个答案:

答案 0 :(得分:0)

您只需要打印字符串:

a = ''' this " is what \"is 'needed' \" Please " '''
print(a)

输出:

this " is what "is 'needed' " Please " 

或者,如果您真的想要外部引号:

print("'" + a + "'")

输出:

' this " is what "is 'needed' " Please " '