与字符串python同时使用单引号和双引号 [英] Use single quote and double quote same time as string python
本文介绍了与字符串python同时使用单引号和双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何与字符串python同时使用单引号和双引号?例如:
How can I use single quote and double quote same time as string python? For example:
string = "Let's print "Happines" out"
结果应为让我们打印快乐"
我尝试使用反斜杠,但它会在应有的斜杠前打印出 \
.
I tried to use backslash but it prints out a \
before 's that should be.
推荐答案
在python中,有很多方法可以编写字符串文字.
In python there's lots of ways to write string literals.
对于此示例,您可以:
print('Let\'s print "Happiness" out')
print("Let's print \"Happiness\" out")
print('''Let's print "Happiness" out''')
print("""Let's print "Happiness" out""")
以上任何一种行为都将符合预期.
Any of the above will behave as expected.
这篇关于与字符串python同时使用单引号和双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文