在Python中给郊,字符串可以使用 ('...'
) 或者 ("..."
) 來表示,效果相同捧灰。在字符串中使用引號(hào)可以用反斜線 \ 淆九。
下面是一些例子
>>> 'spam eggs' # 單引號(hào)
'spam eggs'
>>> 'doesn\'t' # 使用 \' 來跳過引號(hào)作為字符串的標(biāo)記...
"doesn't"
>>> "doesn't" # ...或者可以使用雙引號(hào)達(dá)到同樣效果
"doesn't"
>>> '"Yes," they said.' #反之也可以
'"Yes," they said.'
>>> "\"Yes,\" they said."
'"Yes," they said.'
>>> '"Isn\'t," they said.'
'"Isn\'t," they said.'
英文原文可以參考這個(gè)鏈接。