[Tutor] concat vs join - followup

Kent Johnson kent_johnson at skillsoft.com
Sun Aug 29 02:40:49 CEST 2004


Why do you prefer this way? It seems kind of indirect to me, and much more 
verbose than join(), for example why do you prefer this
>fmt = "%s" * len(strings)
>result = fmt % strings

to this?
result = ''.join(strings)

Kent

At 10:10 PM 8/28/2004 +0100, Alan Gauld wrote:
> > You don't use string formatting to append in a loop do you?
>
>Yes, by building the format string in the loop:
>
>strings = (
>'here is string 1',
>'here is string 2',
>'and finally we have',
>'string 4')
>
>fmt = ""
>
>for s in strings:
>    fmt += "%s"
>
>result = fmt % strings
>
>
>OR in this case more likely I'd do:
>
>fmt = "%s" * len(strings)
>result = fmt % strings
>
>Alan G.



More information about the Tutor mailing list