在引号内使用引号 [英] Using quotation marks inside quotation marks
本文介绍了在引号内使用引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我想在Python中做一个print
命令并且我需要使用引号时,我不知道如何做到不关闭字符串.
When I want to do a print
command in Python and I need to use quotation marks, I don't know how to do it without closing the string.
例如:
print " "a word that needs quotation marks" "
但是当我尝试做我上面做的事情时,我最终关闭了字符串,而且我无法将我需要的单词放在引号之间.
But when I try to do what I did above, I end up closing the string and I can't put the word I need between quotation marks.
我该怎么做?
推荐答案
您可以通过以下三种方式之一进行:
You could do this in one of three ways:
- 同时使用单引号和双引号:
print('"A word that needs quotation marks"')
"A word that needs quotation marks"
- 转义字符串中的双引号:
print("\"A word that needs quotation marks\"")
"A word that needs quotation marks"
- 使用三引号字符串:
print(""" "A word that needs quotation marks" """)
"A word that needs quotation marks"
这篇关于在引号内使用引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文