Can you describe difference between two ways of string concatenation: simple __add__
operator and %s
patterns?
I had some investigation in this question and found %s
(in form without using parentheses) a little faster.
Also another question was appeared: why result of 'hell%s' % 'o'
refers to another memory region than 'hell%s' % ('o',)
?
There is some code example:
l = ['hello', 'hell' + 'o', 'hell%s' % 'o', 'hell%s' % ('o',)]
print [id(s) for s in l]
Result:
[34375618400, 34375618400, 34375618400, 34375626256]
P.S. I know about string interning :)