Question

Which string implementation in python is more pythonic?

string += "<%s>%s</%s>%s" % (a, b, c, d)

or

string += '<' + a + '>' + b + '<'/' + c + '>' + d
Was it helpful?

Solution

String formatting is faster and more readable, always.

Consider using named parameters, and the more recent str.format() method:

"<{tag}>{value}</{tag}>{tail}".format(tag='foo', value='bar', tail='spam')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top