Pregunta

Which string implementation in python is more pythonic?

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

or

string += '<' + a + '>' + b + '<'/' + c + '>' + d
¿Fue útil?

Solución

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')
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top