which is better, string concatentation or substitution?
Leif K-Brooks
eurleif at ecritters.biz
Mon May 8 00:35:51 EDT 2006
John Salerno wrote:
> My initial feeling is that concatenation might take longer than
> substitution
Doesn't look that way:
leif at ubuntu:~$ python -m timeit "'<p>%s</p>\n\n' % 'foobar'"
1000000 loops, best of 3: 0.6 usec per loop
leif at ubuntu:~$ python -m timeit "'<p>' + 'foobar' + '</p>\n\n'"
1000000 loops, best of 3: 0.358 usec per loop
> but that it is also easier to read:
I prefer string formatting for readability, but it's a matter of
personal preference.
More information about the Python-list
mailing list