Single vs. Double Quotes in Python
Python's documentation allows the interchangeable use of single and double quotes for string literals. However, stylistic preferences may arise between the two.
Stylistic Guidelines
Exceptions:
Additional Considerations
Example:
Consider the following code:
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 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
In this example:
The above is the detailed content of When Should I Use Single vs. Double Quotes in Python?. For more information, please follow other related articles on the PHP Chinese website!