3.3.1. Creating strings using quotes#
A string is created by enclosing characters between quotes. Python does not make a difference between single-quotes '
and double-quotes "
. Therefore, the following strings are equivalent:
s1 = "Hello world!"
s2 = 'Hello world!'
Normally, we use double-quotes if the string contains apostrophes '
; inversely, we use single-quotes if the string contains double-quotes "
. For instance, both these strings are correctly defined:
s3 = "It's time to lunch."
s4 = 'I would not call it "results"...'
but the following ones generate syntax errors, because the apostrophe or double-quote closes the string before reaching the ending delimiter:
s5 = 'It's time to lunch'
s6 = "I would not call it "results"..."
Cell In[4], line 1
s5 = 'It's time to lunch'
^
SyntaxError: unterminated string literal (detected at line 1)