首页 > 解决方案 > Python字符串嵌套在字符串下

问题描述

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

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

我希望输出为:

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

问题正在'\'. 任何人都可以提出解决此问题的方法吗?

标签: pythonstringtext

解决方案


你只需要打印你的字符串:

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

输出:

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

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

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

输出:

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

推荐阅读