Python for C++ Programmers
Chapter 2: Basic data types
Multiline strings
You can also write multiline strings with '''triple quotes''' or """triple double-quotes""". The whitespaces (spaces, newlines) are retained.
>>> ''' Never gonna give you up,
... Never gonna let you down,
... Never gonna run around and desert you.
... '''
' Never gonna give you up,\nNever gonna let you down,\nNever gonna run around and desert you.\n'
Advanced note: We talked about multiline comments earlier. These are actually multiline strings, rather than comments. Python processes a multiline string as an expression, but since it is not a statement (e.g. not assigning or returning it), Python does not do anything with it. And this is why it can be used as a multiline comment.
Breaking your string across lines
If you put two strings side-by-side, Python will automatically concatenate the strings.
>>> words = "desert" "you"
>>> words
'desertyou'
Adding a parenthesis will allow you to concatenate strings across lines. This method of using parenthesis/brackets/braces across lines is called implied line continuation.
>>> lyrics = ("Never gonna give you up, "
... "Never gonna let you down, "
... "Never gonna run around and desert you.")
>>> lyrics
'Never gonna give you up, Never gonna let you down, Never gonna run around and desert you.'
Compared to multiline strings, this method will not include any newlines or extra spaces (e.g. from indentation) in your string itself.