在Python中,字符串可以使用 ('...'
) 或者 ("..."
) 来表示,效果相同。在字符串中使用引号可以用反斜线 \ 。
下面是一些例子
>>> 'spam eggs' # 单引号
'spam eggs'
>>> 'doesn\'t' # 使用 \' 来跳过引号作为字符串的标记...
"doesn't"
>>> "doesn't" # ...或者可以使用双引号达到同样效果
"doesn't"
>>> '"Yes," they said.' #反之也可以
'"Yes," they said.'
>>> "\"Yes,\" they said."
'"Yes," they said.'
>>> '"Isn\'t," they said.'
'"Isn\'t," they said.'
英文原文可以参考这个链接。
网友评论