[Tutor] How to break long lines?

Steven D'Aprano steve at pearwood.info
Sat Feb 23 09:43:54 CET 2013

On 23/02/13 13:03, Dave Angel wrote:
> On 02/22/2013 08:22 PM, Jim Byrnes wrote:
>>>   <snip>
>> Thanks for giving me so many options to use in the future.  When reading
>> I completely blew by the single quote on a single line part.  The db is
>> sqlite3 and it seems happy with ''' strings.
> FWIW, there is absolutely no difference between a string object created with single quotes, one created with triple-quotes, or one created by calling some function, or by evaluating some expression.  sqlite3 could not possibly tell the difference, even if it wanted.

This is true. A triple-quoted string on a single line is a single line of text:

s = """Hello world"""

But in general, it is fair to expect that most triple-quoted strings will contain at least one newline, and single-quoted strings generally won't. It might be that some databases dislikes receiving SQL queries containing newlines.

In any case, it bears repeating that strings are strings in Python, whatever delimiters you use. The only difference between single-quoted, triple-quoted, and raw strings, is the parsing rules applied at compile-time, not the object you get at the end.


More information about the Tutor mailing list