Building a multiline string

lallous lallous at lgwm.org
Thu Feb 4 12:34:04 CET 2010


Hello

Maybe that's already documented, but it seems the parser accepts to
build a long string w/o really using the first method:

# Method1
x = "line1" + \ # cannot use comments!
"line2"+ \
"line3"

and instead using a list with one element like this:

# Method2
x = [
"line1" # can use comments
"line2"
"line3"
][0]

Or:
# Method3
x = (
"line1" # can use comments
"line2"
"line3"
)

(Not that I don't want new lines in the strings)

Now should I be using method 2 or 3 in production code?

--
Elias



More information about the Python-list mailing list