[Tutor] concat vs join - followup

Alan Gauld alan.gauld at blueyonder.co.uk
Sat Aug 28 23:10:47 CEST 2004


> 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