Bug or feature: double strings as one

alex23 wuwei23 at gmail.com
Fri Aug 7 13:43:13 EDT 2009


kj <no.em... at please.post> wrote:
> Feature, as others have pointed out, though I fail to see the need
> for it, given that Python's general syntax for string (as opposed
> to string literal) concatenation is already so convenient.  I.e.,
> I fail to see why
>
> x = ("first part of a very long string "
>      "second part of a very long string")
>
> is so much better than
>
> x = ("first part of a very long string " +
>      "second part of a very long string")

My impression is it's mostly for one of clarity. It's especially
useful with regular expressions, as it allows for comments to document
each element of the regex (following example shamelessly taken from
the docs (albeit with personal preferences on formatting))):

re.compile(
    "[A-Za-z_]"       # letter or underscore
    "[A-Za-z0-9_]*"   # letter, digit or underscore
)

Not having the plus sign present does assist (IMO) in the ease of
parsing the regex.
re.compile(



More information about the Python-list mailing list