Python中的单引号与双引号根据文档,它们基本上是可以互换的。是否有一个风格上的理由来使用一个而另一个呢?
3 回答
largeQ
TA贡献2039条经验 获得超8个赞
LIGHT_MESSAGES = {
'English': "There are %(number_of_lights)s lights.",
'Pirate': "Arr! Thar be %(number_of_lights)s lights."}def lights_message(language, number_of_lights):
"""Return a language-appropriate string reporting the light count."""
return LIGHT_MESSAGES[language] % locals()def is_pirate(message):
"""Return True if the given message sounds piratical."""
return re.search(r"(?i)(arr|avast|yohoho)!", message) is not None添加回答
举报
0/150
提交
取消
