【发布时间】:2016-08-02 07:50:56
【问题描述】:
我想加入这一系列的字符串:
my_str='"hello!"' + " it's" + ' there'
希望结果是:
my_str
Out[65]: '"hello!" it's there'
但我明白了:
my_str
Out[65]: '"hello!" it\'s there'
我已经尝试了几次迭代,但似乎都不起作用。
【问题讨论】:
-
你想要得到的结果是不可能实现的。通过不转义
',python 会假定这是字符串的结尾。因此,您需要使用 `` 显式转义它才能正确解析它。您实际上可以在堆栈溢出语法突出显示中很好地看到这一点 -
试试
print(my_str)告诉我们是否真的有问题。
标签: python