Can you describe the difference between two ways to concatenate strings: a simple operator __add__and %spatterns? I had some kind of investigation on this and I found %s(in the form without using brackets) a little faster.
Another question also arose: why does the result 'hell%s' % 'o'relate to a different area of memory than 'hell%s' % ('o',)?
There are several code examples:
l = ['hello', 'hell' + 'o', 'hell%s' % 'o', 'hell%s' % ('o',)]
print [id(s) for s in l]
Result:
[34375618400, 34375618400, 34375618400, 34375626256]
PS I know how to do string interning :)
source
share