matter of style and performance question with string cat'ing

Tim Peters tim.one at home.com
Mon May 7 20:27:09 EDT 2001


[Sean 'Shaleh' Perry]
> I find that I prefer the style:
>
> s = '%s is %s' % (foo,bar)
>
> as opposed to:
>
> s = foo + ' is ' + bar
>
> however, which is more efficient?

Time it, and especially with len(foo) and len(bar) varying over a wide range.

> Usually this does not matter, but I am curious.

Apparently not enough to call time.clock() <wink>.  Throw in

   ' is '.join((foo, bar))

too, while you're at it.





More information about the Python-list mailing list