For example:
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
原文出處
Single quotes vs. double quotes in Python
結論
SQL語句字符串單引號,json數(shù)據(jù)傳遞字符串雙引號甸怕,至于Python欺抗,愛用啥用啥过吻。