[Tutor] Re: Why is this write defined as a tuple,
instead of picking list?
Alan Gauld
alan.gauld at blueyonder.co.uk
Fri Apr 16 18:07:17 EDT 2004
> The relevant line looks like this:
>
> write = "a", "b", "c'
>
> This happens to be syntax for tuples, meaning that write becomes a
tuple. If
> you want to concatenate strings, you should use "+":
>
> write = "a" + "b" + "c"
>
> It is generally not recommended to use this, because it's slow. It's
better
> to have a list of substrings like this:
>
> write = ["a", "b", "c"]
>
> and then use the string method join() to convert that list into a
string
Or even use a format operator with the tuple:
write = "%s%s%s" % ("a", "b", "c')
> In this particular (partial) case, I'd even recommend string
formatting:
>
> write = "<h3>%s</h3>" % article_items[0]
Yes in this case hard coding the <h3> makes even more sense!
And formatting is pretty fast coz it happens in C.
Alan G.
More information about the Tutor
mailing list