Domanda

Which string implementation in python is more pythonic?

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

or

string += '<' + a + '>' + b + '<'/' + c + '>' + d
È stato utile?

Soluzione

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')
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top