Python-在引号内使用引号
发布于 2021-02-02 23:12:29
当我想print
在Python中执行命令并且需要使用引号时,我不知道如何在不关闭字符串的情况下执行该命令。
例如:
print " "a word that needs quotation marks" "
但是,当我尝试执行上面的操作时,我最终关闭了字符串,并且无法将需要的单词放在引号之间。
我怎样才能做到这一点?
关注者
0
被浏览
53
1 个回答
-
你可以通过以下三种方式之一进行操作:
1)一起使用单引号和双引号:
>>> print '"A word that needs quotation marks"' "A word that needs quotation marks"
2)转义字符串中的双引号:
>>> print "\"A word that needs quotation marks\"" "A word that needs quotation marks"
3)使用三引号引起来的字符串:
>>> print """ "A word that needs quotation marks" """ "A word that needs quotation marks"