当我想print在Python中执行命令并且需要使用引号时,我不知道如何在不关闭字符串的情况下执行该命令。
print
例如:
print " "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"
使用三引号引起来的字符串:
print(""" "A word that needs quotation marks" """) "A word that needs quotation marks"